Navigation überspringen

[Gelöst] Do query/filter post without parameter passing

This support ticket is created vor 3 Jahre, 10 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 3 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Christian Cox vor 3 Jahre, 10 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#2136737
Screenshot 2021-08-08 at 4.20.42 PM.png

Dear Sir/Madam,

I don't want to query/filter the post if there is no parameter passing.

Refer to screenshot, I find if I don't pass the url parameter, then the query will do and select the latest post as result. How can I disable the query if there is no url parameter?

Best regards,

Kelvin

#2137943

I think in this case you should change the View's limit from "1" to "No limit". If no URL parameter is included, all results will be displayed. If a URL parameter is included, only the posts in the URL parameter will be displayed.

#2142175

Dear Christian Cox,

I don't want to display all results if no URL parameter is included.

#2143101

So you want to completely disable the View if the cid URL parameter is blank or not present? In that case, you can use a conditional to test the URL parameter value with wpv-search-term. The conditional might look like this:

[wpv-conditional if="( '[wpv-search-term param="cid"]' eq '' )"]
cid param is empty value or not present, like these URLs:
<em><u>versteckter Link</u></em>
<em><u>versteckter Link</u></em>
<em><u>versteckter Link</u></em>
<em><u>versteckter Link</u></em>
Do not place the View here
[/wpv-conditional]

[wpv-conditional if="( '[wpv-search-term param="cid"]' ne '' )"]
cid param is present and not empty value, like these URLs:
<em><u>versteckter Link</u></em>
<em><u>versteckter Link</u></em>
<em><u>versteckter Link</u></em>
<em><u>versteckter Link</u></em>
Place your View here using wpv-view shortcode
[/wpv-conditional]

I think this is the simplest way to achieve what you are looking for in wp-admin. Another solution is to use the Views API Filters like wpv_filter_query and wpv_filter_query_post_process to inspect the $_GET superglobal and modify the query or results programmatically.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process