Hi @sdaviscri,
At the moment the plugin can only filter posts by one taxonomy at a time (categories are taxonomies too, btw.) The limitation exists because there’s no clean way (user-friendly way) to specify terms IDs by taxonomy separately without introducing new parameters and/or ways to pass data in weird formats.
If you want WPP to filter posts by multiple taxonomies (category
and post_format
in your case) you could try hooking into the undocumented wpp_query_where filter hook and add your own WHERE
conditions where (no pun intended) you filter out posts that have the post_format
taxonomy assigned to them.
For example (untested code):
function wp54156_wpp_exclude_post_format($where, $options){
if ( ! is_admin() ){
$where .= " AND p.ID NOT IN (
SELECT object_id
FROM " . $wpdb->term_relationships . " AS r
JOIN " . $wpdb->term_taxonomy . " AS x ON x.term_taxonomy_id = r.term_taxonomy_id
WHERE x.taxonomy = 'post_format' AND x.term_id IN(24)
) ";
}
return $where;
}
add_filter('wpp_query_where', 'wp54156_wpp_exclude_post_format', 10, 2);
Then your shortcode becomes something like:
[wpp cat='-1,-27,-30']
… since you no longer need to use the taxonomy parameter.
Note that using undocumented filter/action hooks is generally not recommended as these might change in the future without any prior notice. After all, they’re for internal use only and shouldn’t be relied upon. With that being said, I generally don’t change stuff around unless it really can’t be helped so I’d say it’s OK to use them (but do keep an eye on the changelog every now and then.)
Filtering multiple taxonomies seemed to work well except for when one was categories. But I’ll give that a shot. That code is more detailed than I really understand but I’ll see what I can get going.
Thanks,
Sean
Filtering multiple taxonomies seemed to work well except for when one was categories.
You sure about that? Because internally WPP uses tax_query to exclude posts by a given taxonomy and according to the documentation the taxonomy
parameter expects a single taxonomy.
… unless you’re confusing taxonomies with term IDs? Because they’re not the same thing: you can filter posts by a given taxonomy (eg. post_tag
) that are associated with several terms IDs (eg. tags).
For example:
[wpp taxonomy="category" term_id='-1,-27,-30']
I was 99% sure, but trying to test now it looks like I’m not.
I had something like [wpp taxonomy="post_format" term_id="22" taxonomy="post_tag" term_id="33"]
and could have sworn it was working, but not anymore. It just uses whatever the last filter is. I also keep getting “Sorry. No data so far.” randomly, which is making it hard to really tell what’s going on.
-
This reply was modified 4 years, 8 months ago by sdaviscri.
It just uses whatever the last filter is.
Correct. That’s the natural behavior of WordPress shortcodes in general. If you repeat a parameter WP will use the last one it finds and pass its value to the caller function, ignoring all previous declarations (which is one of the reasons why WPP can only filter by one taxonomy at a time, although that might change in the future if I find some time to think of a suitable solution that’s also backwards compatible.)
I also keep getting “Sorry. No data so far.”
Hard to say without more details (configuration, active plugins, etc). It could be a number of things. Maybe this can help: I’m getting “Sorry. No data so far”. What’s up with that?
Marking as resolved due to inactivity.