Skip Navigation

[Resolved] Post Title as a select field query filter?

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 9 replies, has 2 voices.

Last updated by lesleeM 2 years ago.

Assisted by: Luo Yang.

Author
Posts
#2478347

Is it possible to set up a selectable dropdown that shows all Post Titles of a custom content type as a filter? I know this is an unusual request. We are trying to set up a page that will allow end-users to filter on Post Title to limit the results on the page to a single post. We will have file fields in a table where they will be downloading the files they are looking for based on the Post Title.

We will also have another filter on this page that will show multiple results. I've already set up that filter. But I see no option to choose Post Title as a Query filter to set up that one. We would like this selectable dropdown to be populated by all Post Titles in the system for this content type.

#2478831

Hello,

Yes, it is an unusual request, and there isn't such kind of built-in feature within Toolset plugins.

By default, the post title search box can only be displayed as single line field.

You might consider custom codes, for example:
1) Create a custom shortcode with custom PHP function:
https://developer.wordpress.org/reference/functions/add_shortcode/

2) In this PHP function, get those posts you want:
https://developer.wordpress.org/reference/functions/get_posts/

3) Output the results as a select dropdown field:
hidden link
Pass one URL parameter to search result page, the parameter value is the post ID.

4) Edit the post view, add a filter by post ID URL parameter
https://toolset.com/course-lesson/filtering-custom-lists-of-posts/#filtering-by-post-id

Then put above custom shortcode into the custom search form

#2480711

I think I'm following your logic completely on this, but the coding skills to do this are way beyond me.

Please confirm if I'm following what you're saying correctly. We need to first create a custom shortcode that will execute a PHP function. The PHP function will get the posts and I can set the post type to Rides to get what we specifically need here. That will then pull all Rides in our system. We can then set the Post Title to show in the dropdown, but the value corresponding to that title will be the Post ID #. You do have Post ID # as a filter in Views, so I'd then be able to use that. Is that following you correctly?

But for my coding skill limitations, for example:

1) On your step 1, I see the sample function code on the page you linked to, and I'd know how to add that to my theme functions.php file, but I wouldn't know how to customize this to make it specific to our needs here.

2) On your step 2, I'm assuming I'd just have to change the 'post type' to 'rides' and 'numberposts' to '1'. and add that function to the theme functions.php file.

3) On your step 3, I wouldn't know how to begin to provide/pull the post title and post id as selectable options from what step 2 does.

4) On your step 4, I'd know how to set up the filter in the View, but I wouldn't know how to get it to use what was created in step 3.

Understood if this is something where we'd need to use your Toolset Contractors section to get this done. Should I post a job request there and reference this ticket?

#2482227

You can provide a test site with the same problem, fille below private message box with login details, also point out the problem page URL and view URL, I can setup a demo for you.

#2483475

I have tried the credentials you provided above, it is not valid, I get below error message:
ERROR: The username or password you entered is incorrect

Please check it, make sure it is valid admin account.

#2484023

Try it again now. It's possible that I clicked the New Password button on the user account but forgot to hit save. If it doesn't work this time, then set up my next reply to be private and I'll change the password again.

#2484369

Thanks for the details, I have done below modifications in your website:
1) Create a post view "Ride post titles dropdown":
hidden link
- Query Ride posts
- In view's loop, display the select dropdown as below:

...
	<select class="ride-post-id" name="wpv-ride-post-id">
      	<option value="">Choose one</option>
		<wpv-loop>
        <option value="[wpv-post-id]" [wpv-conditional if='[wpv-search-term param="wpv-ride-post-id"] eq [wpv-post-id]']selected=selected[/wpv-conditional]>[wpv-post-title]</option>
		</wpv-loop>
    </select>
...

- Enable option "Disable the wrapping DIV around the View "

2) Edit the post view "Ride Maps":
hidden link
In section "Search and Pagination", line 7~10:
Display above post view shortcode:

<div class="form-group">
	<label for="ride-post-id">[wpml-string context="wpv-views"]Choose a Ride[/wpml-string]</label>
	[wpv-view name="ride-post-titles-dropdown"]
</div>

3) Test it in frontend, for example:
hidden link

It works fine, for your reference.

#2485037

Wow! Thanks so much! I'd have never gotten that myself. You guys are awesome. Best support I've ever encountered in the entire computer industry.

It works perfectly. I just had to change the sort order to Post Title Ascending and we have exactly what we need.

So you didn't have to do anything in functions.php? Is this all done exclusively by Views?

Do you guys accept any tips? I feel like we should pay you extra for this level of help.

#2485115

Yes, in this case, it was done all by Toolset plugins, does not need custom codes, you don't need to ad anything into function.php

#2485265

My issue is resolved now. Thank you!