Filter multiple categories
-
I would like to filter the posts by category, showing only those belonging to both catogories.
For example, if I write:
category = "1,2"
I see posts of categories 1 or 2. (boolean OR)
Instead, is it possible to see only posts that are part of category 1 and 2? (boolean AND)
Thank you.
The page I need help with: [log in to see the link]
-
Hello,
When you add the category parameter in the shortcode and pass the multiple category ids, then it will show the posts of respective categories.
For eg : if you are using
category="1"
then plugin will show posts added in category id=1 and if you usecategory="1,2,3"
then plugin will show all posts for category ids = 1,2,3Hello, thanks for the reply.
With
category = "1,2,3"
I can filter all the posts that are part of the category 1 or 2 or 3.I wanted to ask if it was possible to filter only the posts that satisfy the condition of being part of the categories 1 and 2 and 3.
For example.
Post A = category 1,2
Post B = category 1.3
Post C = category 1,2,3With
category = "1,2,3"
I see all three posts.How can I filter only posts that are part of category 1 & 2 at the same time?
I would like the result to show only Post A and Post CIs it possible?
Hello,
Sorry its not possible or i need to check in deep 🙂
Hello @darkmaso
Ok i have one solution where you can achieve this. I have made a small change in grid shortcode file the :
blog-designer-pack –> includes –> Shortcodes –> bdp-post.php
Open this file and go to line #90 where i have added aoperator=> 'AND'
Here is old code:
if($cat != "") { $args['tax_query'] = array( array( 'taxonomy' => BDP_CAT, 'field' => 'term_id', 'terms' => $cat, )); }
Here is updated code:
if($cat != "") { $args['tax_query'] = array( array( 'taxonomy' => BDP_CAT, 'field' => 'term_id', 'terms' => $cat, 'operator' => 'AND', )); }
- This reply was modified 5 years, 11 months ago by pluginandplay.
- This reply was modified 5 years, 11 months ago by pluginandplay.
- This reply was modified 5 years, 11 months ago by pluginandplay.
- This reply was modified 5 years, 11 months ago by pluginandplay.
Hello @darkmaso
Ok i have one solution where you can achieve this. I have made a small change in grid shortcode file the :
blog-designer-pack –> includes –> Shortcodes –> bdp-post.php
Open this file and go to line #90 where i have added aoperator=> 'AND'
Here is old code:
if($cat != "") { $args['tax_query'] = array( array( 'taxonomy' => BDP_CAT, 'field' => 'term_id', 'terms' => $cat, )); }
Here is updated code:
if($cat != "") { $args['tax_query'] = array( array( 'taxonomy' => BDP_CAT, 'field' => 'term_id', 'terms' => $cat, 'operator' => 'AND', )); }
Hi, I saw your second answer on the email. Here it does not appear.
I can not find the “bdp-post.php” file in the “blog-designer-pack” folder. In fact, inside the plugin folder I do not have “blog-designer-pack”. Maybe because I installed the plugin directly from wordpress?
But I understood the change you made, I think it could be something that you can add to the plugin. I find it very useful to filter categories using logical operators to show specific posts on different pages.
Hello @darkmaso
Can you please share the plugin that you are using with a screenshot (under plugin section)?
Hello,
Here you can find our plugin: https://screenshots.firefox.com/JO0KbdzX7D7UMG13/photos.google.com
I have found that you are using lots of plugins BUT your FTP showing few plugins. Are you accessing right FTP?
Hello @darkmaso
Any update?
Hi, I was working on it … I modified the .php file you indicated to me.
Now I do not know what the correct shorcode is for testing it.I tried, without success …
category = "1,2"
category = "1&2"
category = "1,&,2"
category = "1"&"2"
Hi, can you help me with the right syntax?
Hi @darkmaso,
Sorry for the delay.
There will be no change in the shortcode and parameter.
You have to pass categories like this comma separated
category="1,2"
So only those post will come which has category assigned 1 and 2.
Kind Regards,
- This reply was modified 5 years, 11 months ago by pluginandplay.
Hello, thanks for the reply. Now I understand, I had made a mistake.
I modified the file you indicated correctly, but then on wordpress I used
bdp_post_carousel
instead ofbdp_post
.With
bdp_post
it works, but I wanted to use it with the carousel, I tried to copy the same code in the .php of the carousel, in line 108 but in this way the plugin got an error.Hello,
If you open this file : bdp-recent-post-carousel.php then go to line no : 101 and check the code with
if($cat != "") {
Now under this if condition add one more line after
'terms' => $cat
ie'operator' => 'AND'
So complete code will be:
'taxonomy' => BDP_CAT, 'field' => 'term_id', 'terms' => $cat, 'operator' => 'AND',
- The topic ‘Filter multiple categories’ is closed to new replies.