我需要得到与具体职位元帖子。如果我使用以下代码检查常规回路:
$args = array(
\'post_status\' => \'published\',
\'posts_per_page\' => 77,
\'post_type\' => \'post\',
);
$query = new WP_Query($args);
while ($query->have_posts()) : $query->the_post();
$literature = get_post_meta(get_the_ID(), \'popis_literature\');
var_dump($literature);
endwhile;
对于某些帖子
var_dump
提供如下数据数组
array (size=1)
0 =>
array (size=2)
0 => string \'32985\' (length=5)
1 => string \'59956\' (length=5)
如何通过这些ID之一查询帖子?这没有给我任何东西
$args = array(
\'post_status\' => \'published\',
\'posts_per_page\' => -1,
\'post_type\' => \'post\',
\'meta_query\' => array(
array(
\'key\' => \'popis_literature\',
\'value\' => array(\'32985\'),
\'compare\' => \'IN\'
)
),
);
SO网友:maheshwaghmare
您错过了get\\u post\\u meta()中的最后一个参数。
请尝试以下代码:
$literature = get_post_meta(get_the_ID(), \'popis_literature\', true);
它为您提供ID数组。E、 g。
array (size=2) 0 => string \'32985\' (length=5) 1 => string \'59956\' (length=5)
因此,在查询中,您可以像这样使用它们:
$args = array( \'post_status\' => \'published\', \'posts_per_page\' => -1, \'post_type\' => \'post\', \'meta_query\' => array( array( \'key\' => \'popis_literature\', \'value\' => $literature, \'compare\' => \'IN\' ) ), );