我为随机帖子链接编写了简单的代码段:
function ex_get_random_post_link ()
{
$args = array(
'posts_per_page' => 1,
'ignore_sticky_posts' => true,
'post_type' => 'post',
'orderby' => 'rand'
);
$query = new WP_Query($args);
$query->the_post();
return get_permalink();
}
但我希望只发布没有帖子格式的帖子。
答案 0 :(得分:0)
我没有对我的任何wordpress网站使用Post Formats,所以我无法测试这段代码,但试试这个:
function ex_get_random_post_link ()
{
$args = array(
'posts_per_page' => 1,
'ignore_sticky_posts' => true,
'post_type' => 'post',
'orderby' => 'rand',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-quote'
)
)
);
$query = new WP_Query($args);
$query->the_post();
return get_permalink();
}
我不确定如何为帖子格式获取“无”,但行:
'terms' => 'post-format-quote'
是您要更改所使用的帖子格式的地方。
http://wordpress.org/support/topic/post-formats https://wordpress.stackexchange.com/questions/48901/only-get-posts-of-certain-post-formats