【发布时间】:2014-03-29 21:41:37
【问题描述】:
我正在尝试查询将某个 post_object 选为其“父级”的任何帖子。父值必须与当前帖子的 ID 匹配。我已经能够通过查询此帖子类型的所有帖子然后比较循环中的值来复制此功能,如下所示:
<?php
$wp_query = new WP_Query();
$wp_query->query( array (
'post_type' => 'my_post_type',
'meta_key'=>'post_object_field'
));
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$parent = get_field('post_object_field');
$parentId = $parent->ID; ?>
<?php if ($postId == $parentId): ?>
// content
<?php endif; ?>
<?php endwhile; endif; ?>
我想知道是否有办法在查询中检查此值,如果有,是否更快或更正确。
【问题讨论】:
标签: php wordpress custom-fields