2

これは、スタック オーバーフローに関する私の最初の投稿です。

私は WordPress の初心者で、基本的なプロパティ リストを使用する最初のテーマの開発をほぼ完了しました。

ここで確認して、この問題を解決しようとしました..

..多くの Google 検索と同様に。そして、私を助けるものを見つけることができないようです。

「tfg-properties」と呼ばれるカスタム投稿タイプからの投稿を、必要な順序で表示するのに問題があります。

カスタム分類 - 'featured-properties' - functions.php

register_taxonomy('featured-properties', 'tfg-properties', array(
        "hierarchical" => true,
        "label" => "Featured Properties",
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'rewrite' => array( 
            'slug' => 'featured-property',
            'with_front' => false ),
        'public' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        '_builtin' => false,
        'show_in_nav_menus' => false)
    );

この投稿タイプの「featured-properties」と呼ばれるカスタム分類法を作成しました。私がやりたいことは、分類法の「featured-properties」からの投稿を他の投稿の前に表示することです。

カテゴリを使用してこれを達成できますが、ブログも組み込んでいるため、これは機能しません..

これが私の投稿を照会する方法です..

カテゴリ ID で投稿をクエリする - page.php

// Get all posts from featured properties
    $catId = get_cat_ID('Featured Property');

    query_posts('post_type=tfg-properties&cat=' . $catId);

// begin the loop
while( have_posts() ): the_post(); ?>
    <li class="single-prop">
        ...
    </li>
<?php endwhile; ?>

// Get all posts from featured properties

    query_posts('post_type=tfg-properties&cat=-' . $catId);

// begin the loop
while( have_posts() ): the_post(); ?>
    <li class="single-prop">
        ...
    </li>
<?php endwhile; ?>

カスタム投稿をカスタム税で並べ替えて、他の投稿の前に表示する方法はありますか?

前もって感謝します!

4

1 に答える 1

-1

2 つのループを使用できます。最初のループは分類のみを表示し、2 番目のループは分類を除く他のすべてを表示します。

<?php 
$catId = get_cat_ID('Featured Property');
global $post; 

rewind_posts();
$query = new WP_Query(array(
 'cat' => $catId, 
 'post_type' => 'tfg-properties',
));
while ($query->have_posts()) : $query->the_post(); 
?>

<li class="single-prop"></li>

<?php 
endwhile; 
wp_reset_postdata();
?>

<?php 
rewind_posts();
$query = new WP_Query(array(
 'cat' => '-' . $catId, 
 'post_type' => 'tfg-properties',
));
while ($query->have_posts()) : $query->the_post(); 
?>

<li class="single-prop"></li>

<?php 
endwhile; 
wp_reset_postdata();
?>
于 2012-07-16T02:47:34.473 に答える