問題描述

我正在嘗試查詢’quote.’ 的帖子格式的所有帖子我已經將發佈格式添加到我的 functions.php 與

add_theme_support( 'post-formats', array( 'image', 'video', 'gallery', 'quote' ) );

我在管理員中選擇了’quote’ 作為帖子的格式。 Taxonomy_Parameters 中的最後一個示例顯示瞭如何顯示具有’quote’ 格式的帖子,但是當我在主題中運行它時,不會返回任何帖子。這是代碼:

$args = array(
  'tax_query' => array(
    array(
      'taxonomy' => 'post-format',
      'field' => 'slug',
      'terms' => 'post-format-quote'
    )
  )
);
query_posts( $args );

當我只是查詢所有帖子和地點

echo get_post_format();

在循環中,它返回 front-end 上的單詞’quote’ 。另外,當 I var_dump() 的查詢我沒有看到有關 post 格式的數組中的任何東西。

有誰知道是否可以通過郵寄格式查詢?如果是這樣的話

編輯 – 請參閲 Bainternet 的答案下的 5 條評論:這是在一個新的安裝的二十世紀主題的 index.php 上找到的代碼,試圖返回格式類型引號。我返回’no’ 而不是’quote’ 。你能看到我應該改變的東西嗎?

get_header(); ?>
<div id="container">
  <div id="content" role="main">
    <?php $args = array(
      'tax_query' => array(
        array(
          'taxonomy' => 'post-format',
          'field' => 'slug',
          'terms' => array('quote')
        )
      )
    );
    query_posts( $args );
    if ( have_posts() ) : while ( have_posts() ) : the_post();
      echo get_post_format();
    endwhile; else:
      echo 'no';
    endif;
    wp_reset_query();
    ?>
  </div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

編輯 2 – 似乎 WordPress Codex 現在已經更改,分類參數部分僅在 Google 緩存中找到。

編輯 3 – 最終工作代碼

$args = array(
  'tax_query' => array(
    array(
      'taxonomy' => 'post_format',
      'field' => 'slug',
      'terms' => 'post-format-quote'
    )
  )
);
query_posts( $args );

twenty-ten 編輯形式的第一個編輯將是…

get_header(); ?>
<div id="container">
  <div id="content" role="main">
    <?php $args = array(
      'tax_query' => array(
        array(
          'taxonomy' => 'post_format',
          'field'    => 'slug',
          'terms'    => 'post-format-quote'
        )
      )
    );
    query_posts( $args );
    if ( have_posts() ) : while ( have_posts() ) : the_post();
      the_title();
      echo get_post_format();
      echo '<br />';
    endwhile; else:
      echo 'no';
    endif;
    wp_reset_query();
    ?>
  </div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

最佳解決方案

這段代碼不正確!你有

'taxonomy' => 'post-format'

但它真的需要:

'taxonomy' => 'post_format'

沒有下劃線,查詢將無效。拉我的頭髮幾個小時後,我剛剛在我的 WordPress 3.1 安裝上測試了這個。

希望有幫助!

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。