Post Selection Module in Fluent Forms
Fluent Form brings an awesome feature called Post/CPT Selection. It can fetch any post-type data on your website and show them in a dropdown. So without any more time lost, let’s jump into the topic.
What is Post/CPT Selection?
If you put this field in your form, then users can see posts within your site, select any post from the dropdown, and submit their other data. You can also specify the post you want to show your users.
For example, if you make a post edition form where users can edit their published form, now you want to show a dropdown of each post that particular user has posted; you can use a query to show all the posts where the author is that particular user. It will bring all the post titles, so the user can just select that particular post and submit other data.
How does it work?
- Just add the Post/CPT Selection field from the available Advanced Fields, and it will add the Post Selection dropdown for you.
- By default, it will show all posts listed on your site. But you can select any other post-type data within your site.
- But if you want to show the post based on single or multiple criteria, you need to use the Extra Query Parameter field.
How Extra Query Parameter Works
It works with all WP Query. You can see the WP_Query documentation here.
But to be able to run the same queries inside the Extra Query Parameter field, you need to write the queries in a certain format. Just go to the WordPress wp_query documentation and from there, choose how you want to display your post ex: author name, category name, tag and etc. Now assume I have a post author named Kevin, and we want to show all the posts he has so we can use this in our query.
In wp_query, it works as below –
- Now we will convert it to our way. We will grab the key and value from above.
We will write this way –
- Also, we can pass multiple parameters and values by using & in between them.
Parameters in Array
If your query contains array types values, for example:
You need to use this way –
Parameters in Nested Array
If your query contains nested array types values, for example:
It would be best if you used this way –
That’s how you can use the Post Selection Module in Fluent Forms.