Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Petros Charitopoulos
Petros Charitopoulos
21,396 Points

Wordpress | Search Results from Custom Post Types

I have the below loop for bringing the results from a Custom Post Types only search. It works fine by bringing the title of the post but I am trying to add also the additional fields which are associate with every post.

<?php global $query_string;

$query_args = explode("&", $query_string); $search_query = array();

foreach($query_args as $key => $string) { $query_split = explode("=", $string); $search_query[$query_split[0]] = urldecode($query_split[1]); } // foreach

$my_query = new WP_Query('meta_value='.$s); ?> <?php if (!empty($my_query->posts)) : ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- the second meta_value searh loop --> <?php endwhile; ?> <?php endif; ?> </div> </div>

Any idea on how can I add the fields in the search results?

Thanks!