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]
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
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?
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
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.