簡體   English   中英

Wordpress:查詢頁面自定義字段中給出的“ category_name”

[英]Wordpress: Query 'category_name' given in page custom field

我想從頁面的自定義字段中指明的“ category_name”中查詢帖子。 換句話說,我可以使用自定義字段值填充下面的查詢嗎?

  <?php query_posts( array ( 'category_name' => '[from custom field]', 'posts_per_page' => -1 ) ); ?>
  <?php while (have_posts()) : the_post(); ?>
    ...
  <?php endwhile; ?>

有人知道我會怎么做嗎? 任何幫助,將不勝感激。 謝謝。

如果我對您的理解正確,則應執行以下操作:

<?php 
$category_name = get_post_meta( $post->ID, 'custom_field_name', true );
query_posts( array ( 'category_name' => $category_name, 'posts_per_page' => -1 ) );
while (have_posts()) : the_post(); ?>
    ...
<?php endwhile; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM