{"id":3997,"date":"2020-08-07T14:20:15","date_gmt":"2020-08-07T18:20:15","guid":{"rendered":"https:\/\/themespress.ca\/?p=3997"},"modified":"2021-11-16T21:21:54","modified_gmt":"2021-11-17T02:21:54","slug":"shortcode-wp-display-or-send-post-id-content-via-formidable-form","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/shortcode-wp-display-or-send-post-id-content-via-formidable-form\/","title":{"rendered":"Shortcode WP: Display or send post ID content via Formidable Form"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Shortcode WP: In this tutorial, we will show you how to create a Formidable form which in turn will be used to display a post ID&#8217;s content in a user&#8217;s email. First, we need to create a form that will allow us to choose the title of our post or the title. <\/p>\n<p>Our newly created form will include two fields: Email and Select. In our example below, our Select field will allow us to display all post existing titles, publish and then convert them into selectable choices in the Select field. <\/p>\n<p>In order to do so, we will use Populate Fields which will insert all post titles into our Select field. <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-6252435\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-6252435\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"custom\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_filter(&#039;frm_setup_new_fields_vars&#039;, &#039;add_a_field_function_formidable&#039;, 20, 2);\nadd_filter(&#039;frm_setup_edit_fields_vars&#039;, &#039;add_a_field_function_formidable&#039;, 20, 2);\n \nfunction add_a_field_function_formidable($values, $field){\n        \/\/ Changer le ID 154 par le ID de votre champ formidable form\n\tif($field-&gt;id == 154){\n\t\t$arrayPositions = array();\n\t\t$pushobj = array(\n\t\t\tvalue =&gt; &quot;&quot;,\n\t\t\tlabel =&gt; &quot;S&eacute;lectionnez votre article&quot;\n\t\t);\n\t\tarray_push($arrayPositions, $pushobj);\n\t\t$positionQuery = new WP_Query( array( &#039;post_type&#039; =&gt; &#039;post&#039;, &#039;posts_per_page&#039; =&gt; -1, &#039;orderby&#039; =&gt; &quot;menu_order&quot;, &#039;order&#039; =&gt; &quot;ASC&quot;) );\n\t\tif ( $positionQuery-&gt;have_posts() ) {\n\t\t\twhile ( $positionQuery-&gt;have_posts() ) {\n\t\t\t\t$positionQuery-&gt;the_post();\n\t\t\t\t$pushobj = array(\n\t\t\t\t\tvalue =&gt; get_the_title(),\n\t\t\t\t\tlabel =&gt; get_the_title()\n\t\t\t\t);\n\t\t\t\tarray_push($arrayPositions, $pushobj);\n\t\t\t}\n\t\t\twp_reset_postdata();\n\t\t}\n \n\t   \t$values[&#039;options&#039;] = $arrayPositions;\n\t}\n\treturn $values;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>We will now use a function that wil fetch the ID of the post selected in the form. <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-3957734\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-3957734\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"custom\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">function get_post_by_title($page_title, $type = &quot;post&quot;, $output = OBJECT) {\n\tglobal $wpdb;\n\t$post = $wpdb-&amp;gt;get_var ( $wpdb-&amp;gt;prepare ( &quot;SELECT ID FROM $wpdb-&amp;gt;posts WHERE post_title = %s AND post_type=&#039;$type&#039;&quot;, $page_title ) );\n\tif ($post)\n\t\treturn get_post ( $post, $output );\n\treturn null;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Now let&#8217;s create a shortcode that will generate the content of the post selected by the user so he can receive it by email. <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-4458942\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-4458942\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"custom\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">function via_create_shortcode_questions_reponses(){\n\t\/\/ Changer votre id par le field de votre champ select Titres des articles\n        $title          = do_shortcode( &#039;[frm-field-value field_id=154]&#039; );\n\t$post_id        = get_post_by_title($title);\n\t\n\t$content = get_post_field(&#039;post_content&#039;, $post_id);\n\treturn $content;\n}\nadd_shortcode( &#039;reponse&#039;, &#039;via_create_shortcode_questions_reponses&#039; ); <\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>This feature of quick form can be easily displayed in a sidebar thanks to the Formidable form widget allowing you to select which form to display.<\/p>\n<p>NB:  Please make sure to do a back up of your th\u00e8me, files and database before proceeding with these tutorials. <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Shortcode WP: In this tutorial, we will show you how to create a Formidable form which in turn will be used to display a post ID's content in a user's<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/shortcode-wp-display-or-send-post-id-content-via-formidable-form\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4905,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[351,313],"class_list":["post-3997","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-forms","tag-plugins"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/3997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=3997"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/3997\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4905"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=3997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=3997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=3997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}