• 24-04-2022, 21:08:55
    #1
    Aşağıdaki kodun içerisinde değişken kullanmam gerekiyor ama çalışmıyor, nedenini anlamadım?

    Çalışan kod;

    $the_query = new WP_Query( array(
        'post__in' => array(
            16405,16362,16290,16434,16661
        ),
    ) );
    Çalışmayan kod;
    $featured_content_id = get_theme_mod( 'laura_featured_content_id' );
    $the_query = new WP_Query( array(
    'post__in' => array(
    $featured_content_id
    ),
    ) );
    $featured_content_id değişkenine echo ve var_dump() ile bakınca doğru görünüyor. Yani sonuç 16405,16362,16290,16434,16661 şeklinde ama array içerisinde çalışmıyor. Direk $featured_content_id = '16405,16362,16290,16434,16661'; yapınca da çalışmıyor. İlla array içerisine yazmak zorunda mıyım?
  • 27-04-2022, 20:06:25
    #2
    Konu hakkında halen yardıma ihtiyacım var, çözemiyorum.
  • 27-04-2022, 20:15:15
    #3
    Developer
    $featured_content_id = get_theme_mod( 'laura_featured_content_id' );
    $the_query = new WP_Query( array(
    'post__in' => $featured_content_id,
    ) );
  • 27-04-2022, 20:27:57
    #4
    brown adlı üyeden alıntı: mesajı görüntüle
    $featured_content_id = get_theme_mod( 'laura_featured_content_id' );
    $the_query = new WP_Query( array(
    'post__in' => $featured_content_id,
    ) );
    Hata verdi hocam. post__in içerisine ID'leri yazmakla ilgili dökümanda birkaç farklı özel not düşmüş ama anlayamadım hangisinin teknik olarak ne işe yaradığı ve çözümün o olup olmadığını.

    Kaynak: https://developer.wordpress.org/refe...sses/wp_query/

    Alıntı:
    Açıklaması:
    post__in (array) – use post ids. Specify posts to retrieve. ATTENTION If you use sticky posts, they will be included (prepended!) in the posts you retrieve whether you want it or not. To suppress this behaviour use ignore_sticky_posts.

    NOTE: Ticket #28099: Passing an empty array to post__in will return has_posts() as true (and all posts will be returned). Logic should be used before hand to determine if WP_Query should be used in the event that the array being passed to post__in is empty.


    ‘post__in‘ – Preserve post ID order given in the post__in array (available since version 3.5). Note – the value of the order parameter does not change the resulting sort order.

    Aldığım hata şöyle:
    ( ! ) WARNİNG: ARRAY_MAP(): EXPECTED PARAMETER 2 TO BE AN ARRAY, STRİNG GİVEN İN C:WAMP64WWWMYVWP-İNCLUDESCLASS-WP-QUERY.PHP ON LİNE 2113
    ( ! ) WARNİNG: İMPLODE(): INVALİD ARGUMENTS PASSED İN C:WAMP64WWWMYVWP-İNCLUDESCLASS-WP-QUERY.PHP ON LİNE 2113
  • 27-04-2022, 20:35:49
    #5
    Developer
    $featured_content_id = get_theme_mod( 'laura_featured_content_id' );
    $query = new WP_Query( array( 'post_type' => 'post', 'post__in' => array( $featured_content_id ) ) );
    dener misiniz
  • 27-04-2022, 20:45:57
    #6
    brown adlı üyeden alıntı: mesajı görüntüle
    $featured_content_id = get_theme_mod( 'laura_featured_content_id' );
    $query = new WP_Query( array( 'post_type' => 'post', 'post__in' => array( $featured_content_id ) ) );
    dener misiniz

    Sadece 1. ID için içerik geliyor hocam. 2. 3. 4. ve 5. yok.
  • 27-04-2022, 20:52:40
    #7
    @brown; Tamamdır hocam çözüldü konu çok teşekkür ederim. Şöyle olması gerekiyormuş:

     'post__in' => array_map('intval', explode(',', $featured_content_id)),