Comments (1)
You can now pass an id to the shortcode and get that id in the filter hook.
for example
[ajax_filter_posts id="only-vegan-recipes"]
/**
* Add the diet term on all the queries made with the shortcode ajax_filter_posts
*
* @param array $query_args query arguments set by the plugin Ajax Filter posts
* @param array $shortcode_attributes all shortcode attributes
*
* @return array a updated list of query arguments
*/
function my_site_set_additional_term_for_ajax_filter_posts($query_args, $shortcode_attributes) {
// Only show posts with the term vegan in the diet taxonomy for the shortcode with the id only-vegan-recipes
if (!empty($shortcode_attributes['id']) && $shortcode_attributes['id'] === 'only-vegan-recipes') {
$diet_tax_query_args = [
[
'taxonomy' => 'diet',
'field' => 'slug',
'terms' => 'vegan',
],
];
// If there are already tax queries args set, merge my query args with the set args
if ( !empty( $query_args['tax_query'] ) ) {
$prev_set_tax_args = $query_args['tax_query'];
$query_args['tax_query'] = [
// Set the relationship to AND: we want only post with my term and the set terms by the user
// Also see https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
'relation' => 'AND',
$diet_tax_query_args,
$prev_set_tax_args
];
return $query_args;
}
// If there are no tax queries args already set, just add it
$query_args['tax_query'] = $diet_tax_query_args;
}
return $query_args;
}
add_filter('ajax_filter_posts_query_args', 'my_site_set_additional_term_for_ajax_filter_posts', 10, 2);
from wordpress-ajax-filter-posts.
Related Issues (20)
- Make string 'toon meer' en 'toon minder' translatable
- Remove opinionated styling: more focus on the core concept of this plugin AJAX fetching and filtering
- Create a way to add this plugin as a composer package
- Initiate the plugin without the use of a shortcode
- Add the ability set a WordPress filter on the posts query arguments HOT 8
- There is an option to sort order and order by? HOT 3
- Issue loading posts HOT 9
- Don't allow users to set different post types in the AJAX call
- Post status HOT 2
- Clear button HOT 2
- Hook to override template HOT 3
- Trigger filter selection with hash url HOT 1
- Load more HOT 2
- meta key HOT 1
- JSON Parse error HOT 1
- See all terms even if there is no product linked to one of them HOT 2
- It is not possible to set specific styling for a taxonomy filter list
- It is not possible to have a filter that selects just one and deselect other options on select
- Accessibillity could be better
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-ajax-filter-posts.