WordPress自定义查询后格式


WordPress custom query post-format

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

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

但是我只想获得没有帖子格式的帖子。

我不为

我的任何 wordpress 网站使用帖子格式,所以我无法测试此代码,但请尝试以下操作:

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-formatshttps://wordpress.stackexchange.com/questions/48901/only-get-posts-of-certain-post-formats