Skip Navigation

[Resolved] Creating a Saved Search From View Filters To a CPT

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

Our next available supporter will start replying to tickets in about 1.31 hours from now. Thank you for your understanding.

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)

This topic contains 2 replies, has 2 voices.

Last updated by Timothy 6 years, 12 months ago.

Assisted by: Shane.

Author
Posts
#594339

Hi,

I know Toolset doesn't have Saved Search functionality where a user can perform a search with filters then save that search to use later. But I'm wondering if it might be possible with a CRED form and a CPT. If I were to create a CPT called Saved Searches containing the fields (Start Time, End Time, Day, Type) and then when a user filters and clicks the Save Search button it accesses the url parameters and populates those to a CRED Form that the user can save/submit to the cpt. So an example URL like:

hidden link

would then populate the type-happyhour form field with Food, and the happy-hour-days field with Monday, etc. They click Save and it creates a new post in the Saved Searches cpt that I could then use Access to allow only that user to access.

Sound possible? If so I think the main area I'd need help with is getting the URL parameters to populate that CRED form fields.

Tim

#594502

Shane
Supporter

Languages: English (English )

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

Hi Timothy,

Thank you for contacting our support forum.

Actually this is possible and all you need to do is create a cred form and a custom field to hold the url.

Then add it to the page then use some jquery to copy the search url into the CRED form so that the user can save the search .

Take a look at the link below on how to add get the url using javascript https://stackoverflow.com/questions/406192/get-current-url-in-javascript

Thanks,
Shane

#595053

Thank you. This worked!

And if anyone needs to do something similar here is the javascript I used in the CRED form to get the browsers URL to populate a field:

jQuery(document).ready(function(){
        $(".btn").click(function(){
            
            var pageURL = $(location).attr("href");
           
            document.getElementsByClassName('search-url').value = pageURL; 
            $('.search-url').val(pageURL);
			
         
        });
    });
    
    jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
      $(".btn").click(function(){
            
            var pageURL = $(location).attr("href");
			
             $('.search-url').val(pageURL);
            document.getElementsByClassName('search-url').value = pageURL; 

        });
});

And the form:

[credform class='cred-form cred-keep-original']

	[cred_field field='form_messages' value='' class='alert alert-warning']

	<div class="form-group">
		[cred_field field='post_title' post='saved-search' value='' urlparam='' class='form-control search-name' output='bootstrap' placeholder='Search Name']
	</div>

	<div class="form-group search-url-container">
		[cred_field field='search-url' post='saved-search' value='' urlparam='' class='form-control search-url' output='bootstrap'  name='search-url' id="search-url"]
	</div>

    <button type="button" class="saved-search-button" style="display:none;">Get URL</button>

	[cred_field field='form_submit' value='Save Search' urlparam='' class='btn btn-primary btn-lg saved-search-button' output='bootstrap' type="button" ]

[/credform]

Tim