Skip Navigation

[Resolved] Accessing IDs of posts found in search/filter

This support ticket is created 2 years, 6 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Simon Logan 2 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2186929

Tell us what you are trying to do?
When users perform a search/filter on our site I'd like to be able to use pass some of the information from those results to another form on the same page.

So after a search is performed we have a button which can be clicked on which triggers a form to pop up and I'd like to use the Name and ID (ideally) of each result from the search to populate a checkbox list on our form. It's a Formidable Form so I already have a function in place to create the options for us which is all users of a certain role on the site, however I want this list to only show those users who have shown up in the search results.

Is there any documentation that you are following?
I thought that https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process might be the best filter to use but wasn't sure how to access the information from the search (I'd tried $query->posts() but that didn't seem to return any value).

#2187485

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

Can you please share temporary admin login details, along with the link to the page with the form and the view? I'll be in a better position to guide you with the next steps, accordingly.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2188891

Hi Waqar

I just wanted to check you got my previous private message? Not to chase you, it's just that normally you guys are really quick in responding so it's unusual to go more than day without a response so just wanted to make sure.

#2188931

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the admin access.

Earlier, when I checked the form, all users with the "Lender" role were showing, but now only two of them are there.

You can revert back any changes you've made so that all the "Lender" users are showing in the form and then follow these steps:

1. As the value for these checkboxes is using the 'usernames', you can include the hidden usernames of all the post authors whose results are showing, in the bottom of view's loop item template:


<div class="lenders-container" style="display:none;">[wpv-post-author format="meta" meta="user_login"]</div>

Note: These usernames will be hidden, but we'll be able to read them through a custom script.

2. In the CSS editor of the view, you'll include some code so that all lender user options are hidden, when the form initially loads:


#form_applyforterms #frm_field_10_container .frm_checkbox {
display: none;
}

3. In the view's JS editor, you can include the following custom script, which executes, whenever the popup with ID "2178" is loaded/shown. The script will read all the hidden usernames of lenders whose posts are available in the view's results and then make only their respective checkbox option visible in the form:


jQuery( document ).on( 'elementor/popup/show', ( event, id, instance ) => {
	if ( id === 2178 ) {
		var names = [];
		jQuery( ".lenders-container" ).each(function( index ) {
			var txt = jQuery( this ).text();
			names[index] = txt;
		});

		jQuery.each(names , function(index, val) { 
			jQuery( "#frm_field_10_container input[value='"+val+"']" ).closest( ".frm_checkbox" ).css( "display", "block" );
		});
	}
});

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2189753

Thanks for the guidance, Waqar, initially I'd been looking to see if there was a way of accessing the results via PHP/functions file as this tends to be my preference (to manipulate the data *before* it is passed to the user's browser) however this solution at least does achieve what we need.

I was also able to manipulate it a bit to suit us more specifically which is great. The only bit which tripped me up initially was which J/S box to add the script to as on a View there is a JS box for the loop itself and also the loop item template, however it would seem to make sense that it would go into the first box (the loop one) rather than the loop item, as I imagine this will mean the j/s would get output for each result in the search.

(Just in case that latter info was useful for anyone else reading this).

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.