Skip Navigation

[Resolved] Don't query if no url parameter in view

This support ticket is created 3 years, 2 months ago. 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.

This topic contains 3 replies, has 2 voices.

Last updated by kelvinL-2 3 years, 2 months ago.

Author
Posts
#2251501
Screenshot 2021-12-23 at 9.56.53 PM.png

Dear Sir/Madam,

I want to add a page to query custom posts by entering the post id.

Below is the content in my Loop Editor

[wpv-conditional if="( '[wpv-search-term param="cid"]' ne '' )"]
[wpv-layout-start]
	[wpv-items-found]
    <div class="table-responsive-sm">
      <table class="table  table-striped">
        <thead class="thead-dark">
          <th>Post ID</th>
          <th>Name</th>
        </thead>
        <tbody>
	<!-- wpv-loop-start -->
        <div class="container wpv-loop js-wpv-loop">
          <wpv-loop wrap="1" pad="true">
            [wpv-item index=1]
            <div class="row ">
              <div class="col-md-12">[wpv-post-body view_template="loop-item-in-judge-query-v2"]</div>
            </div>
            [wpv-item index=other]
            <div class="col-md-12">[wpv-post-body view_template="loop-item-in-judge-query-v2"]</div>
            [wpv-item index=pad]
            <div class="col-md-12"></div>
            [wpv-item index=pad-last]
            <div class="col-md-12"></div>
            </div>
          </wpv-loop>
        </div>
      <!-- wpv-loop-end -->
		</tbody>
      </table>
[wpv-pager-nav-links output="bootstrap"]

</div>

      [/wpv-items-found]
      [wpv-no-items-found]
      <strong>[wpml-string context="wpv-views"]暫沒有記錄[/wpml-string]</strong>
      [/wpv-no-items-found]
      [wpv-layout-end]
[/wpv-conditional]

If I set the Display to no limit, then it will take a bit long of a time to display the search form, but my result may not only have 1 post.

I add

[wpv-conditional if="( '[wpv-search-term param="cid"]' ne '' )"]
...
[/wpv-conditional]

outside the [wpv-layout-start]...[wpv-layout-end] but it won't stop the query if there is no parameter cid passing in Url, please advise how I can stop the query when I newly load the page.

Best regards,

Kelvin

#2251627

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Let me see if I have understood you correctly.

You have added a View to a page (or template?), and you only want to show the results of the View *if* a URL parameter cid is provided.

If the cid parameter is missing, the View results should not be shown, is that correct?

In which case, rather than put the wpv-conditional shortcodes inside the View output, I think the best option is to use the wpv-conditional shortcode on the page where you insert the View, and add the View inside the conditional shortcode.

That way if the condition fails (no cid URL parameter) then the View simply will not be processed at all.

#2251913

Dear Nigel,

Done, many thanks!

#2251915

My issue is resolved now. Thank you!