soflyy / oxygen-bugs-and-features

Bug Reports & Feature Requests for Oxygen
https://oxygenbuilder.com/
315 stars 30 forks source link

Advanced Query Option to Modify Current Query instead of Creating a New Query #3138

Open maltmann-muc opened 1 year ago

maltmann-muc commented 1 year ago

WordPress does a great job in creating dynamic queries from the URL like for post archive (blog), taxonomy archive, search, etc. Oxygen Advanced Query does a great job for creating custom queries by offering a sophisticated UI.

Unfortunately, you can't combine those two: Either have the default dynamic WP query, OR have a fancy UI to create a new static custom query. Currently, the only way to modify the default query is by implementing a "pre_get_posts" hook function.

Feature I'd like to suggest Option for Advanced Query to modify the current query instead of creating a new query.

I'm aware it will be a challenge to implement appropriate logic to the modifications, e.g.

What are the use cases for this feature? This new feature would allow to modify default criteria without losing the power of WP's default dynamic query. And without the need to manually implement a "pre_get_posts" hook function.

Typical query parameters that would often need to be modified for default queries are:

Some real world use cases which currently require a pre_get_posts hook function are described in Yan Kiara's Gist: https://gist.github.com/yankiara/c43da83662a14e7609b4e23f6d82717a

Examples of this feature or functionality. If another product has done it well, provide examples here. Not aware of any. You could be the first to offer this genius feature ;-)

krstivoja commented 1 year ago

++ 1

RaulGandia commented 1 year ago

+1

gabrieluntura commented 1 year ago

+1

andreslotta commented 1 year ago

Examples of this feature or functionality. Bricks is an example. It merges the main query for archive and search pages with custom query settings by default. If you do not want this behavior for specific queries you can disable it using a filter: https://academy.bricksbuilder.io/article/filter-bricks-posts-merge_query/.

Vyyt02 commented 1 year ago

+1

bsymptom commented 1 year ago

+1

Esnola commented 1 year ago

+1

robert1112 commented 1 year ago

+1

blakerr commented 1 year ago

+1

arsh999cg commented 1 year ago

+++++++++++++++++++++++++++++++=1

MrKubb commented 1 year ago

+1

22onn22 commented 1 year ago

+1

Esnola commented 1 year ago

+10

maltmann-muc commented 1 year ago

Examples of this feature or functionality. Bricks is an example. It merges the main query for archive and search pages with custom query settings by default. If you do not want this behavior for specific queries you can disable it using a filter.

Thank you, @andreslotta, for this precious additional input. I never used Bricks enough to be aware of this feature.

Your description reads "you can disable it using a filter". That's kinda similar (roughly, and in the opposite way) to using a pre_get_posts action in Oxygen. Having a simple toggle could still beat Bricks ;-)

675056817 commented 1 year ago

+

bramminzo commented 1 year ago

YES, would very much like this feature!

GSlattz commented 1 year ago

+1 Would be a great addition to Oxygen

idemaublanc commented 1 year ago

+1

Spellhammer commented 8 months ago

@maltmann-muc Can you explain a scenario where you'd want to modify a default query's tax_query?

maltmann-muc commented 8 months ago

@maltmann-muc Can you explain a scenario where you'd want to modify a default query's tax_query?

@Spellhammer, you're investigating/working on it? ❤️

tax_query sample: (from my head) Default category archive query uses a tax_query to dynamically select the current category, e.g. 'projects'. I often had the requirement to add a negative filter, like show all of 'projects', but not those with secondary category 'hidden'. The default tax_query is probably something like (simplified)

[
  [
    'taxonomy' => 'category',
    'field' => 'term_id',
    'operator' => 'IN',
    'terms' => get_queried_object_id(),
  ]
]

I wanna add my filter to produce something like this:

[
  'relation' => 'AND',
  [
    'taxonomy' => 'category',
    'field' => 'term_id',
    'operator' => 'IN',
    'terms' => get_queried_object_id(),
  ],
  [
    'taxonomy' => 'category',
    'field' => 'slug',
    'operator' => 'NOT IN',
    'term_ids' => 'hidden',
  ]
]
Spellhammer commented 8 months ago

Thanks @maltmann-muc!