Answer the question
In order to leave comments, you need to log in
Where to rest (official docs) about displaying entries from 2 categories /category/slug1+slug2 (AND)?
Wordpress can display posts from 2 categories /category/slug1+slug2
Where can I read about this in the wordpress documentation?
ps
Can't do this when using the no category base plugin, which removes /category/ from the URL? I want to know if there is a way to solve this problem.
Answer the question
In order to leave comments, you need to log in
It's best to see what's going on under the hood. Using the Query Monitor plugin, you can see the resulting query and analyze it. I specifically created several categories and posts, and for debugging one post I assigned 3 categories, one of which is a child category of another (only hardcore!):
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
LEFT JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_relationships AS tt1
ON (wp_posts.ID = tt1.object_id)
LEFT JOIN wp_term_relationships AS tt2
ON (wp_posts.ID = tt2.object_id)
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (2,3,4)
AND tt1.term_taxonomy_id IN (1)
AND tt2.term_taxonomy_id IN (3) )
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'acf-disabled'
OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 10
WHERE (
wp_term_relationships.term_taxonomy_id IN (2,3,4)
AND
tt1.term_taxonomy_id IN (1)
AND
tt2.term_taxonomy_id IN (3)
)
/**
* Generate a link for multiple categories
*
* @param $categories array An array of category slugs
*
* @return string
*/
function my_categories_link( $categories ) {
$category_base = get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category';
$categories_str = implode( '+', $categories );
return sprintf( "%s/%s/%s/",
home_url(),
$category_base,
$categories_str
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question