How to use a custom field value as a search parameter value in query_posts
-
I’m dealing with two custom post types here: shows and bios.
On the shows single-post page, I’d like to include two excerpts from posts in the bios section.
Right now I’m just keeping it simple and only pulling in the_title while I figure out the loop.
<?php global $post; $myposts = query_posts('numberposts=50&post_type=bios&name=Scott Amendola'); foreach($myposts as $post) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?>
In the query_posts, as an example I have “Scott Amendola” as the value of the name parameter. Instead of me hardcoding that value, I’d like to to be based on the values of set in custom fields on the shows page.
I know this won’t work, but this is what I’m getting at:
<?php global $post; $myposts = query_posts('numberposts=50&post_type=bios&name=$custom_name_here'); foreach($myposts as $post) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?>
Where it says $custom_name_here, I need that to be a variable set in the custom fields on the Shows Add New page.
Any ideas on how to make this happen?
- The topic ‘How to use a custom field value as a search parameter value in query_posts’ is closed to new replies.