Support » Themes and Templates » how to query custom post type on search results

  • Resolved jobmeer


    I created one custom post type called ‘members’ with different custom fields (with the plug-in custom field template). On the search.php I like to show the results of ‘members’ post type and the regular post type. Because members have to echo different custom fields I like to chance the design of the entry ‘members’. How can I query the custom post type ‘members’? If I use

    //The Query
    //The Loop
    if (have_posts()) : ?>

    the query shows al members post and not only the one which contains the search results.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thanks for Reply. But it’s not that I want to change the look in .ccs but like to apply the loop two times.

    One for all the search results of custom ‘member’ post and one for all the search results of regular post.

    Normally on other pages I can query the loop with the above query code, but for search results this is not working. The query shows all the posts from custom ‘member’ post and not the search result.

    What I’m suggesting is something like this in The Loop on your search template:

    if ($post->post_type == 'members') {

    Thanks michaelH for your response. This is working perfect. Thanks…

    I created a different output for members and for the regular posts results:

    <?php if (have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>"> 
    	<?php  if ($post->post_type == 'members') {
    	//Add a custom value
    	$place=get_post_custom_values('Name');echo $place[0];
    	<?php  if ($post->post_type == 'post')  {?>
    	<div id="titel_post"><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><small>		 	<?php edit_post_link('Edit this entry &raquo;', '', '  '); ?> </small>
    	<?php the_excerpt(); ?>
    	<?php }?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to query custom post type on search results’ is closed to new replies.