WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to query custom post type on search results (5 posts)

  1. jobmeer
    Member
    Posted 3 years ago #

    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

    <?php
    //The Query
    query_posts('post_type=members');
    //The Loop
    if (have_posts()) : ?>

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

  2. MichaelH
    Member
    Posted 3 years ago #

  3. jobmeer
    Member
    Posted 3 years ago #

    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.

  4. MichaelH
    Member
    Posted 3 years ago #

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

    if ($post->post_type == 'members') {
    the_meta();
    }
  5. jobmeer
    Member
    Posted 3 years ago #

    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(); ?>
    	</div>
    	<?php }?>

Topic Closed

This topic has been closed to new replies.

About this Topic