我有一个meta_key
使用名称director
在我的帖子中,我试图显示所有有价值的帖子,比如christian bale
in控制器meta_key
, 我想在single中使用此查询。php,在新查询中不显示当前帖子
谢谢你的帮助
我有一个meta_key
使用名称director
在我的帖子中,我试图显示所有有价值的帖子,比如christian bale
in控制器meta_key
, 我想在single中使用此查询。php,在新查询中不显示当前帖子
谢谢你的帮助
例如,如果你想得到一个演员的职位,有不同的解决方案,但在我看来,最好是使用tag
作为演员的名字,或post meta
. 目前我给你的解决方案是使用WordPress搜索系统并尝试查找帖子。
// We try to get post for Christian bale as a keyword
$args = array(
\'post_type\' => \'post\',
\'post__not_in\' => array(get_the_ID()), // We don\'t need the current post
\'s\' => \'christian bale\', // We put the Christian Bale search here
);
// Or as a meta value
$args = array(
\'post_type\' => \'post\',
\'post__not_in\' => array(get_the_ID()), // We don\'t need the current post
\'meta_key\' => \'director\',
\'meta_value\' => \'christian bale\',
);
$films = new WP_Query($args);
// If there\'s posts, show it
if($films->have_posts())
{
while($films->have_posts())
{
$films->the_post();
the_title();
the_content();
}
}
// Reset query
wp_reset_query();
在帖子之后或帖子中使用此选项,可以显示包含“christian bale”文本的帖子。嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post