You'reYou are going to need set up a new WP_Query in your content-*.php
with the correct parameters in order to send it into a loop.
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'recipes',.
'field' => 'slug',
'terms' => 'dessert',
)));
$your_posts = new WP_Query( $args );
?>
You can add any other parameters you want/need for this query. You can find more reference on parameters at the WordPress Codex page for WP_Query and add them to the $args
array.
In my example, WP_Query
is going to look at the recipes
taxonomy, it's going to find recipes
by looking at the slug, and find all posts with the value dessert
.
Once you have the new WP_Query set up, you then send it into the WordPress loop:
<?php
if ( $your_posts->have_posts() ) : while ( $your_posts->have_posts() ) : $your_posts->the_post();
?>
// Your Post Stuff Goes Here
<?php endwhile; else: ?> <p>Sorry, there are no posts to display</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
In order to get at your custom fields, I would suggest writing a function in your functions.php
file to handle this and call it within the loop. That way if you can use it throughout the theme with more ease.
<?php
function my_custom_field( $id, $field_name ) {
return get_post_meta( $id, $field_name, true );
}
?>
What this function does is access the post's metadata, look for the field name you specify, and returns a single value. If there are multiple values using the same key, then omit the true
and the function will instead return an array which you can then use a foreach()
to process that.
So, for example, say your custom field is 'mood'
then the call to the function would be:
<?php my_custom_field( $post->ID, 'mood' ); ?>