如果我可以过滤搜索结果基于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