For all of my pages I have setup a taxonomy field using the plugin Advanced Custom Fields, for which I can then select as Home
category, or something else like News
. I am using the default category option, not a custom taxonomy.
I have a custom post type slides_post_type
where for each new slide
I am selecting the relevant category, i.e. Home
.
The code I am using at present to output the slides is:
<?php
$slides_category = get_field('slider_category');
$args = array(-
'post_type' => 'slides_post_type',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( $slides_category ),
),
),
);
$query = new WP_Query( $args );
$my_secondary_loop = new WP_Query( $args );
if( $my_secondary_loop->have_posts() ): while( $my_secondary_loop->have_posts() ): $my_secondary_loop->the_post(); ?>
//Post content goes here
<?php endwhile; ?>
This should be that where my page is set to Home
and my slides are set to the same category it should show those slides
. However this code is not outputting anything.
Any suggestions?
-
in this line$args = array(-
just a typo. Also, the value stored inslider_category
, does that match the slug or name of the category. If the value in your field matches the name of the category, your query won't work