0

我为随机帖子链接编写了简单的片段:

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();
}

但我只想发布没有帖子格式的帖子。

4

1 回答 1

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

于 2013-09-09T18:41:36.523 回答