Skip Navigation

[Resolved] Select CPT with dropdown and button, as per post #1217023

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

Problem:

Setup a jump menu using Views.

Solution:

I suggest you use post ID as the URL parameter, for example:

https://toolset.com/forums/topic/select-cpt-with-dropdown-and-button-as-per-post-1217023/#post-1835167

Relevant Documentation:

This support ticket is created 4 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.

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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by neilR 4 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1834099

I am trying to replicate myleneB's solution here https://toolset.com/forums/topic/dropdown-menu-of-post-type/#post-1217023
I have a CPT 'street', and want to give the user a dropdown of streets plus button, so when street is selected and button pressed, they are taken to the street's page.
CPT slug is 'street'
I have used the following code in the Loop Editor, which is my interpretation of myleneB's description. The dropdown appears fine, but form submission takes me to a 404, with <mysiteurl>/street/ showing in the browser address bar.
If I put <mysiteurl>/street/ in the browser address bar, it shows the street archive, and <mysiteurl>/street/<street-slug> shows the street's page, which is where I'd like the form to be sending me...

I cannot find any technical documentation on the Toolset site about filter triggers, only the high-level block-based tutorial. Please advise, thanks.

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<form action="<mysiteurl>/street/" method="post">
<select name="street[]" class="js-wpv-filter-trigger wpcf-form-select form-select select" data-currentposttype="street">
<option value="0" selected="selected" class="wpcf-form-option form-option option">Select your street</option>
<wpv-loop>
<option value="[wpv-post-slug]" class="wpcf-form-option form-option option">[wpv-post-title]</option>
</wpv-loop>
</select>
<input type="submit" class="wpv-submit-trigger js-wpv-submit-trigger btn" name="wpv_filter_submit" value="Go">
</form>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#1835167

Hello,

I suggest you use post ID as the parameter, for example, modify the codes you mentioned above as below:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<form action="[wpv-bloginfo show="url"]" method="post">
<select name="p" class="js-wpv-filter-trigger wpcf-form-select form-select select" data-currentposttype="street">
<option value="0" selected="selected" class="wpcf-form-option form-option option">Select your street</option>
<wpv-loop>
<option value="[wpv-post-id]" class="wpcf-form-option form-option option">[wpv-post-title]</option>
</wpv-loop>
</select>
<input type="submit" class="wpv-submit-trigger js-wpv-submit-trigger btn" name="wpv_filter_submit" value="Go">
</form>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Above codes will construct a form, pass post ID as value the parameter "p" to your website "siteurl", and WP will redirect you automatically.

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-bloginfo

#1835421

Hi Luo,
That worked great, thanks, with one line tweaked. In the Form Action, I changed the quotes to single, and because the single post url is <mysite>/street/<street-slug>, I got a 404 until I added /street/ into the action.
[code]
<form action="[wpv-bloginfo show='url']/street/" method="post">
[/code]

One additional query generated by the above. While this form takes the user to the relevant street single post, the url in the browser bar still shows the shorter <mysite>/street/ - and I have a different submission form on that template, set to 'replace the form with a message' on submission: when that form is submitted, of course the archive page is shown because the browser url is refreshed.... I can work around this by changing the form to 'show a page', but wondered if there was a quick solution?

#1836033

Are you going to display the result in a new page? if it is, you can add a target="_blank" into theHTML form tag, see below document:
hidden link

#1839181

Hi Luo,
Sorry, I wasn't clear. The form on the 'street' page is a different form (one to edit the CPT), and when it was submitted, the page reloaded /street/ rather than /street/streetname/. Problem was solved very simply, by ticking 'Submit this form without reloading the page (use AJAX)' and displaying a message instead of the form. Thanks for your help.