I have a client who wants me to create a field in the form where the customer can select additional products to add to their quote. The products are set up as posts. I am using a WordPress installation, with Elementor Pro and Dynamic ooo plugins, and I was able to create a call to collect all the post titles using:
Using the Elementor Pro using Dynamic ooo Token: [query:post] (as seen in the image)
Here are the options in Elementor Pro Forms Module
This is what the form looks like when you try to select an option
The issue I am having is that it is bulking the post titles into one giant select item rather than single selection items separated by the post title. What I want to happen is that I can call all the post titles, and they will populate into separate the items into a multi-select where any of the post titles can be selected and added to their quote request. Does anyone have an idea of how to do this?
Here is the link to see what I am doing:
http://www.closeout.gbwcompanies.com/product-closeouts/stone-veneer-closeouts/blue-ridge-matterhorn/
Click on the blue button to Request a Quote and the form popup should show you what I am talking about. You will see the select list on the first step of the form with all the post titles in one long item.
Here is a link to the Dynamic ooo docs that I used to get me this far:
Dynamic ooo Docs for Tokens
Edited:
Here is a code I am currently trying but is not working:
function get_posts_title_filter($data) {
global $post;
$args = array( 'cat' => 4 );
$myposts = get_posts( $args );
$data = '<select select name="lstdate" id="prods" onchange="document.getElementById('prods').value=this.value;"><option></option>';
foreach( $data as $title ) {
$output.=$title.' ';
}
foreach ( $myposts as $post ) : setup_postdata($post);
$title = get_the_title();
$output .= '<option value="'. $title .'">'. $title .' </option>';
endforeach;
$data .= "</select>";
return var_dump($data);
}
2
Answers
I just figured out the answer to my question. I am so sorry for not seeing this sooner. I found this article Tokens Collection Link
If you are looking to do this, use the following shortcode: [query:posts|options]
i don’t have the plugin. So i can test myself and give you final working solution. But from what i have after read the Dynamic ooo docs, this might be work:
open your theme’s functions.php file.
insert this codes at very bottom (above php close tag "?>" if have) and save it:
in your token setting, using this token:
if you get any error, send back to me for debug and correction.