admin管理员组文章数量:1415673
OK, very simple task, I'm just not good at PHP.
I have a page where I want to list some staff using a styled list. Here is the page all working fine, I just need to divide the results - /?post_type=people
I downloaded a "custom content type" plugin and added the content type of "people" and added the appropriate fields. Now I want to filter the posts I have added by the custom field called "hierarchy".
Here is how I want the page to display:
Notice in the image I have headings for each group of posts filtered by the room. The custom field "hierarchy" contains the room variables of either "management", "babies_room" and "toddlers_room".
How do I amend the code below to filter the posts by the value held within <?php print_custom_field('hierarchy'); ?>
?
<?php $col = 1; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($col == 1) echo "<div class=\"row\">"; ?>
<div class="post col<?php echo $col;?>" id="post-<?php the_ID(); ?>">
<div class="people-spacer">
<div class="people"><a class="animate" >
<div class="bio">
<p class="titles"><?php the_title(); ?><br/>
<span class="job"> <?php print_custom_field('job'); ?></span> </p><br />
</div>
<img src="<?php print_custom_field('staff_image:to_image_src'); ?>" width="160" height="160" alt="<?php the_title(); ?>-image" />
</div>
<div class="people-link-edit"><?php edit_post_link('Edit Post', ''); ?></div>
</div>
</div>
<?php if ($col == 1) echo "</div>"; (($col==1) ? $col=2 : $col=2); ?>
<?php endwhile; ?>
OK, very simple task, I'm just not good at PHP.
I have a page where I want to list some staff using a styled list. Here is the page all working fine, I just need to divide the results - http://www.themontessoripeople.co.uk/montesori/?post_type=people
I downloaded a "custom content type" plugin and added the content type of "people" and added the appropriate fields. Now I want to filter the posts I have added by the custom field called "hierarchy".
Here is how I want the page to display:
Notice in the image I have headings for each group of posts filtered by the room. The custom field "hierarchy" contains the room variables of either "management", "babies_room" and "toddlers_room".
How do I amend the code below to filter the posts by the value held within <?php print_custom_field('hierarchy'); ?>
?
<?php $col = 1; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($col == 1) echo "<div class=\"row\">"; ?>
<div class="post col<?php echo $col;?>" id="post-<?php the_ID(); ?>">
<div class="people-spacer">
<div class="people"><a class="animate" >
<div class="bio">
<p class="titles"><?php the_title(); ?><br/>
<span class="job"> <?php print_custom_field('job'); ?></span> </p><br />
</div>
<img src="<?php print_custom_field('staff_image:to_image_src'); ?>" width="160" height="160" alt="<?php the_title(); ?>-image" />
</div>
<div class="people-link-edit"><?php edit_post_link('Edit Post', ''); ?></div>
</div>
</div>
<?php if ($col == 1) echo "</div>"; (($col==1) ? $col=2 : $col=2); ?>
<?php endwhile; ?>
Share
Improve this question
edited Aug 25, 2019 at 20:44
Glorfindel
6093 gold badges10 silver badges18 bronze badges
asked Sep 25, 2012 at 14:00
Sue.My.ChinSue.My.Chin
31 bronze badge
1 Answer
Reset to default -1Something like this should work:
meta_key=hierarchy&meta_value=management
This should be added into the query_posts function, that is not shown in your code block, but should come before it.
本文标签: phpHow do I filter a custom post type loop by a field
版权声明:本文标题:php - How do I filter a custom post type loop by a field? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745215748a2648156.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论