简体   繁体   English

如何将 ACF get_field 放在数组 post__in Wordpress 中

[英]How to place ACF get_field inside an array post__in Wordpress

I have the code below but it's just posting one post or showing 1 post but if i add the post id inside the array it working, but if i add the $tguides_value its just showing one item我有下面的代码,但它只是发布一个帖子或显示 1 个帖子,但如果我在数组中添加帖子 ID 它工作,但如果我添加$tguides_value显示一个项目

<?php
  $tguides_value = get_field('recommended_tguides');

         $args = array(

            'post_type' => 'travelguides',
            'posts_per_page' => 3,
            'post__in' => array($tguides_value),

Question: How would I place the ACF get_field inside the array post__in in Wordpress问题:如何将 ACF get_field放在 Wordpress 中的数组post__in

Try using as follows,尝试使用如下,

$tguides_value = get_field('recommended_tguides', $postID);

         $args = array(

            'post_type' => 'travelguides',
            'posts_per_page' => 3,
            'post__in' => array($tguides_value),

You need to turn your text field return of a string into an array by exploding at the comma, you can't just pass your text string into it as an array.您需要通过在逗号处展开将字符串的文本字段返回转换为数组,您不能只将文本字符串作为数组传递给它。

<?php
  $tguides_value = get_field('recommended_tguides');
  $tguides_array = explode (",", $tguides_value);

         $args = array(

            'post_type' => 'travelguides',
            'posts_per_page' => 3,
            'post__in' => $tguides_array,

I figured this out thanks to your help Daniel Vickers, but it should be implode instead of explode .感谢 Daniel Vickers 的帮助,我弄明白了这一点,但它应该是implode而不是explode

Here is what I ended up doing for myself in my particular use and it worked:这是我最终在我的特定用途中为自己做的事情并且它有效:

    <?php
    $values = get_field('homepage_magic_test');
    $valuett = implode(",",$values);
    ?>
    <?php get_jig(array(
        'img_alt_field' => 'alternate',
        'title_field' => 'title',
        'recent_posts' => 'yes',
        'recents_title_override' => 'custom_title',
        'recents_post_type' => 'page',
        'post_ids' => $valuett
    ));
        ?>

So I assume the following would work for the code above.所以我假设以下内容适用于上面的代码。

$tguides_value = get_field('recommended_tguides');
$tguides_imp = implode(",",$tguides_value);

         $args = array(

            'post_type' => 'travelguides',
            'posts_per_page' => 3,
            'post__in' => $tguides_imp,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM