Skip Navigation

[Resolved] Custom post Archive custom search

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to start their archive search with an empty result page first, then display the results after a search has been made.

Solution:

You can do this by using our conditionals to check for URL parameter that would appear after the search has been done.

Have a look at this example below.

[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
    <ul class="wpv-loop js-wpv-loop">
        <wpv-loop>
            <li>[wpv-post-body view_template="loop-item-in-cars"]</li>
        </wpv-loop>
    </ul>
    <!-- wpv-loop-end -->
[/wpv-conditional]

We are using the [wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"] shortcode to check if the [wpv-search-term param='wpv_view_count'] shortcode is empty. If this 'wpv_view_count' shortcode is not in the url then it would mean a search has not yet been done.

This way we can use this to hide the results unless a search has been done.

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

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by tipinoncomuni 5 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1320177
Schermata 2019-08-20 alle 15.44.16.png

- Tell us what you are trying to do?

Sorry for this stupid question but i were unable to find an answer in Toolset documentation and/or examples.
I need a Custom Post Archive custom search page with empty list displayed until user enter a valid code and clicks on search button.
So i want a page with only search form displayed, then, when the user insert a code and clicks on search button, the resulting custom post list appear under the form.
At this time, when i load the page, all the custom posts are displayed under the search form.
The same happens if i use a View instead of an Archive

Is there any documentation that you are following?
NO

Is there a similar example that we can see?
NO

What is the link to your site?
here is the page
hidden link

Here are mine ...

... - QUERY FILTER
see image

... - SEARCH AND PAGINATION
[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
<label for="wpv-wpcf-codice-fiscale">[wpml-string context="wpv-views"]Codice Fiscale[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-codice-fiscale" url_param="cf" placeholder="00000000000"]
[wpv-filter-submit name="Cerca" output="bootstrap"]
</div>
[/wpv-filter-controls]
[wpv-filter-end]

... - LOOP EDITOR
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-body view_template="loopitem-in-privacycondominio"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]Codice Fiscale non trovato.[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#1320385

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for getting in touch.

What you can do is to try the code below and see if it helps.


add_filter( 'wpv_filter_query', 'show_empty_results_default_func', 10,2 );
function show_empty_results_default_func( $query_args, $setting ) {
    if($setting['view_id'] == 9999){  
  
        if( !isset($_GET['wpv_view_count'])){
            $query_args['post__in'] = array(0);
        }
  
    }
    return $query_args;
}

Add it to your toolset custom code in Toolset -> Settings -> Custom Code and then activate it. Note you will need to change the 9999 to the ID of your archive.

Please let me know if this helps.
Thanks,
Shane

#1320611

Thanks Shane, It works for the custom View
hidden link

but not for the Custom Post Archive.
hidden link

is it easy to correct?

#1320639

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

A quick simple solution you can do is to use our conditional shortcode to check for a specific url parameter.

Take a look at this example below.

[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<li>[wpv-post-body view_template="loop-item-in-cars"]</li>
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
[/wpv-conditional]

I'm checking the wpv_view_count param is present in the url. If it isn't then the results are hidden. Once this parameter is available then the results will be show.

Just copy this to your site and it should work.

Note you will need to replace

  • [wpv-post-body view_template="loop-item-in-cars"]
  • with the one generated on your archive.

    Thanks,
    Shane

    #1320815

    My issue is resolved now. Thank you!