Post Selection Module in WP Fluent Forms
Fluent Form brings a new 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 lose 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 your post that what you want to show to 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 just 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 it works?
Just add the new “Post Selection Block” and it will add the post selection dropdown for you.
By default, it will show all posts list within 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 post that he has so how we can use this in our query.
In wp_query, it works as bellow:
Now we will convert it to our way. We will grab key and value from above.
We will write this way:
Also, we can pass multiple parameter 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:
You need to use this way:
Using Dynamic Shortcodes in Query Parameter
We have dynamic shortcode options, you can fetch dynamic shortcodes from your any input fields, you just have to click on Advanced Options and you will see “Dynamic Default Value” field there. For example we want to grab the “Current User’s Username”, we can grab the shortcode like this:
Now just Cut this text from there.
We can use the shortcode in our dynamic parameter as below:
That’s how you can use the Post Selection Module in WP Fluent Forms.