如果我可以過濾搜索結果基於post_type過濾搜索結果while循環自定義字段名稱
在:if ($post->post_type == "mobile-experience") { ?>
如何添加兩個過濾器,將篩選結果基於自定義字段名稱
我曾嘗試:
if ($post->post_meta == "mobile_app") { ?>
但不起作用。
自定義字段名稱爲'Mobile App
'。
我想在3個自定義字段名稱下顯示搜索結果;沒有用。
<?php
// Start the Loop.
while (have_posts()) : the_post();
if ($post->post_type == "mobile-experience") { ?>
<?php get_template_part('search-mobile-experience'); // works
}
if ($post->post_meta == "mobile_app") { ?> // Doesn't work
<?php get_template_part('new-mobile-app_template');
}
else { ?>
更新:週四下午1:15($#& !!)
非常感謝您的意見傢伙;這讓我瘋狂。以下是我目前擁有的。但仍然出現我的自定義字段過濾器被忽略。
<?php
// Start the Loop.
while (have_posts()) : the_post();
if ($post->post_type == "mobile-experience") { ?>
<?php get_template_part('search-mobile-experience');
}
if (get_post_meta($post->ID, 'mobile_app', true) == "mobile_app") { ?>
<?php get_template_part('new-mobile-app-template');
}
else { ?>
<p><?php the_date(); ?></p>
<?php get_template_part('content', get_post_format());
}
endwhile;
else :
// If no content, include the "No posts found" template.
get_template_part('content', 'none');
endif;
?>
然後,我有2個模板:
new-mobile-app-template.php
和
search-mobile-experience.php
(最終我將有一個第三,或自定義字段過濾器2)
這兩個看起來像這樣:
<?php
/**
* The default template for displaying content. Used for both single and index/archive/search.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if (is_sticky() && is_home() && ! is_paged()) : ?>
<div class="featured-post">
<?php _e('Featured post', 'twentytwelve'); ?>
</div>
<?php endif; ?>
<header class="entry-header">
<?php the_post_thumbnail(); ?>
<p>Mobile Website | March 28, 2014 </p>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
</header><!-- .entry-header -->
<div class="entry-summary">
<?php the_excerpt(); ?>
<?php if ((get_custom_field('Objective')) !== ''): ?>
<?php print_custom_field('Objective'); ?>
<?php endif ?>
</div>
</article>
<!-- #post --><hr />
我的目標是有一個搜索結果頁面有3類:
文章(所有文章和頁面除了2個下文提到的自定義字段)
{Search Results}
自定義字段#1
{搜索結果}
自定義字段#2
{搜索結果}
感謝這看起來很棒,但仍然沒有工作;我已更新我的問題,有什麼建議? – 2014-10-30 20:30:14