Not working all the way
-
Hi i have the plugin working to post to the back end but i need it to post a set of ACF fields to a post. I can not get that to work.
I added the code to functions php with my key and it still only posts to the back end not creating a new post.
Is there some way to change a saved back end post into a live post from the back end that would be nice to approve each one.
Or I just need to get it working.
Thanks
-
Hi! I hope you are enjoying Advanced Forms.
I’m not quite sure I understand where your problem is. Have you been following this guide: https://advancedforms.github.io/guides/advanced/setting-up-a-form-to-create-posts/? If so could you post what your code looks like?
Thanks!
Here is the code i put in.
<?php
function generate_post_from_form_submission() {
// Get the submitted field values
$post_title = af_get_field( ‘post_title’ );
$post_content = af_get_field( ‘post_content’ );// Set up a form using the values for post title and content
// Replace post_type with whatever type of post you want to generate
$post_data = array(
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’,
‘post_title’ => $post_title,
‘post_content’ => $post_content,
);// Create post with the previously retrieved values
wp_insert_post( $post_data );}
add_action( ‘af/form/submission/key=form_592a78ec63524’, ‘generate_post_from_form_submission’, 10 );/**
* GeneratePress functions and definitions
*
* @package GeneratePress
*/// No direct access, please
if ( ! defined( ‘ABSPATH’ ) ) exit;define( ‘GENERATE_VERSION’, ‘1.3.46’ );
define( ‘GENERATE_URI’, get_template_directory_uri() );
define( ‘GENERATE_DIR’, get_template_directory() );
—————————————————————It just adds it to the back forms area. I need it to make a post.
Here is a test fill in, http://rvparkphotos.com/fill-in/
Thanks
I’m guessing this is in your theme’s functions.php?
One thing that might cause some trouble are your field names. In my code example the post title and content are picked up from fields called
post_titleandpost_content, looks like this in the code:`
$post_title = af_get_field( ‘post_title’ );
$post_content = af_get_field( ‘post_content’ );
`Your form doesn’t seem to have these two fields and you might have to change them to match your own fields names. Judging by your site these seem to be simply
titleandcontent. Your code should then be:`
$post_title = af_get_field( ‘title’ );
$post_content = af_get_field( ‘content’ );
`Try it out and get back to me!
I out that in and it killed my site.
Parse error: syntax error, unexpected ” );’ (T_CONSTANT_ENCAPSED_STRING) in /home3/mo91412/public_html/rvparkphotos.com/wp-content/themes/generatepress/functions.php on line 12
Had to remove all of it to get the site back up
I put it back in and it did not crash the site but it is still not creating a post it is still just posting into the Entries area in the back.
<?php
function generate_post_from_form_submission() {
// Get the submitted field values
$post_title = af_get_field( ‘title’ );
$post_content = af_get_field( ‘content’ );// Set up a form using the values for post title and content
// Replace post_type with whatever type of post you want to generate
$post_data = array(
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’,
‘post_title’ => $post_title,
‘post_content’ => $post_content,
);// Create post with the previously retrieved values
wp_insert_post( $post_data );}
add_action( ‘af/form/submission/key=YOUR_FORM_KEY’, ‘generate_post_from_form_submission’, 10 );I see i forgot the key so put that in still not working to post
<?php
function generate_post_from_form_submission() {
// Get the submitted field values
$post_title = af_get_field( ‘title’ );
$post_content = af_get_field( ‘content’ );// Set up a form using the values for post title and content
// Replace post_type with whatever type of post you want to generate
$post_data = array(
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’,
‘post_title’ => $post_title,
‘post_content’ => $post_content,
);// Create post with the previously retrieved values
wp_insert_post( $post_data );}
add_action( ‘af/form/submission/key=form_592a78ec63524’, ‘generate_post_from_form_submission’, 10 );I think I’m going to have to dig a bit deeper. Do you think you could get me temporary access to your WordPress install and your FTP?
It would great if you could. Please send credentials to my personal email address which you can find here: http://fabianlindfors.se
This has been resolved in a separate mail conversation.
The problem was that the field name strings used in af_get_field where not valid PHP strings because they were written with unusual quotes. The form now works as intended after changing to regular single quotation marks (‘).
The topic ‘Not working all the way’ is closed to new replies.