I'm banging my head here. I can't seem to figure out what's wrong with this it works although if a post has more than two categories is doesn't seem to show. What is wrong here?
<div class="base-column">
<button class="accordion">How To <img src="/wp-content/uploads/sites/2/2018/11/expand-button.jpg"></button>
<div class="panel">
<?php // How To
$args_1 = array(
'post_type' => 'post',
'category__and' => array(117,123),
);
// The Query
$the_query_1 = new WP_Query( $args_1 ); ?>
<?php // The Loop
if ( $the_query_1->have_posts() ) {
while ( $the_query_1->have_posts() ) {
$the_query_1->the_post(); ?>
<strong>
<a class="title-article" href="<?php echo the_permalink(); ?>">
<?php echo get_the_title(); ?>
</a>
</strong><br>
<?php }
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
?>
</div>
</div>
I'm banging my head here. I can't seem to figure out what's wrong with this it works although if a post has more than two categories is doesn't seem to show. What is wrong here?
<div class="base-column">
<button class="accordion">How To <img src="/wp-content/uploads/sites/2/2018/11/expand-button.jpg"></button>
<div class="panel">
<?php // How To
$args_1 = array(
'post_type' => 'post',
'category__and' => array(117,123),
);
// The Query
$the_query_1 = new WP_Query( $args_1 ); ?>
<?php // The Loop
if ( $the_query_1->have_posts() ) {
while ( $the_query_1->have_posts() ) {
$the_query_1->the_post(); ?>
<strong>
<a class="title-article" href="<?php echo the_permalink(); ?>">
<?php echo get_the_title(); ?>
</a>
</strong><br>
<?php }
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
?>
</div>
</div>
Share
Improve this question
edited Nov 16, 2018 at 18:34
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Nov 16, 2018 at 17:57
Mark AnthonyMark Anthony
359 bronze badges
1 Answer
Reset to default 0You need to edit line 7.
'category__and' => array(117,123),
The category__and parameter doesn't use a string for the category IDs. Write the array like this:
'category__and' => array(
'117',
'123'
)
);