donglei1973 2015-06-16 11:41
浏览 61

Wordpress:自定义帖子类型查询未找到高级自定义字段meta_query

I have a custom post type in Wordpress called People (each post in people is a person with some bio details etc).

Inside each People post I've created a custom field called 'tags' which has a series of checkboxes.

If someone clicks on the System Manager checkbox I want to be able to only pull through all the system managers on a particular page.

The most success I've had is using the wp_get_recent_posts instead of new wp_query .. this will output everybody UNTIL I add my extra meta query search. Then nothing appears.

$people_args = array(
    'post_type' => 'people',
    'post_status'=>'publish',
    'meta_query' => array(
    array(
        'key' => 'tags', // name of custom field
        'value' => 'systemmanager',
        'compare' => 'LIKE'
    )
    )
);
$people_posts = wp_get_recent_posts($people_args);
foreach( $people_posts as $people ){    

    $fields = get_fields($people["ID"]);

    if (get_post_thumbnail_id( $people["ID"] )>0) {
        $myimgsp = wp_get_attachment_image_src(get_post_thumbnail_id($people["ID"]),'full');
        echo '
            <li class="item">
                <a href="'.get_permalink(43).'"><img src="'.$myimgsp[0].'" alt="'.$people["post_title"].'" class="img-responsive" /></a>
                <div class="profile">
                    <h3>'.$people["post_title"].'</h3>
                    <p>'.$fields["job_title"].'</p>
                    <a href="'.get_permalink(43).'"  class="btn invert black">View Profile</a>
                </div>

            </li>';
    }
}
wp_reset_query();

I've been stuck on this for hours trying out all the different types of loops but I've had no luck. Has anyone come across this problem before?

  • 写回答

2条回答 默认 最新

  • dongshuan8722 2015-06-16 12:06
    关注

    If you got stuck on the query maybe try different approach and use the post_id from the query and make small loop inside your code there use get_post_meta(post_id) to check the meta key and get the tags value... something like this...

    $meta = get_post_meta($post_ID);
    foreach($meta as $key=>$val)
        {
            if ($key == 'tags')
            echo $val;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)