Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability set a WordPress filter on the posts query arguments #18

Closed
Robbertdk opened this issue Mar 7, 2021 · 8 comments
Closed

Comments

@Robbertdk
Copy link
Owner

This creates the capability of a developer set extra arguments on the initial query and the queries with the activated filters.
For example to add specific ordering, pagination or other tax query arguments.

@andreacreativesoft
Copy link

andreacreativesoft commented Mar 7, 2021

Hi guys, I need some help, im there but not :-)

I'm trying to do this: I need to filter posts - first if defined by Category xxx, yyy, zzz - if not defined in the shortcode then all Categories but only those that have a defined TAG -or TAGS in the shortcode. Then on filter change to category yyy - have just those that are in Category yyy and have the TAG or TAGS defined

Ex:

Categories: Boston, Texas, New York ...
Tags: News, Events, Spotlights...

Show all posts with TAG = Spotlights and in categories Texas, New York ( if no Categories defined in the shorcode take all )
then in the filter to show just those with TAG ( Tags defined ) but from selected Category

@Robbertdk
Copy link
Owner Author

@andreacreativesoft As discussed in the mail I can look next week at this.

But feel free to create a pull request or fork the project if you need that functionality this week.

The initial query and the filtered queries all pass through this function: https://github.com/Robbertdk/wordpress-ajax-filter-posts/blob/master/class-ajax-filter-posts.php#L280
You can combine the given $args with the specific arguments you want to alter the query.

See also the docs to create nested taxonomy queries: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

@andreacreativesoft
Copy link

andreacreativesoft commented Mar 9, 2021 via email

@Robbertdk
Copy link
Owner Author

@andreacreativesoft Can you show the code changes you've made? Then I can take a quick look at it.

@andreacreativesoft
Copy link

andreacreativesoft commented Mar 11, 2021 via email

Robbertdk added a commit that referenced this issue Mar 14, 2021
…Issue #18

Add a wrapper function for WP_Query calls with the filter ajax_filter_posts_query_args  so developers can alter the quries
@Robbertdk
Copy link
Owner Author

Robbertdk commented Mar 14, 2021

@andreacreativesoft I've added a filter hook to allow developers to alter the query. See the example in the Readme to use that filter hook for adding a extra term to the query https://github.com/Robbertdk/wordpress-ajax-filter-posts#query-arugments

@andreacreativesoft
Copy link

andreacreativesoft commented Mar 30, 2021 via email

@Robbertdk
Copy link
Owner Author

@andreacreativesoft I've added the option to pass an id as an attribute to your shortcode, which you can get in your filters hooks. With that you can decide how to alter your queries by the given id. See #23 for an example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants