So I have a custom post type that I use with a field group
This is the code that creates the form.
acf_form(array(
'id' => 'POV-Travel',
'post_id' => 'new_post',
'field_groups' => array(431),
'new_post' => array(
'post_type' => 'pov_travel',
'post_status' => 'publish'),
'submit_value' => 'Submit',
));
Is it as simple as adding the Adsense code just above or below the ‘submit_value’?
So you think looping through hundreds of posts to get the total for all posts everytime a specific page is loaded is more efficient than pulling that data out of the DB?
I’m asking because I have no idea.
Thanks John,
For anyone else that may be interested, I also had to move the echo outside the loop. Working code below.
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'pov_travel'
));
if( $posts ):;
$dla = 0;
foreach( $posts as $post ):
$dla += get_field ('dla');
endforeach;
echo $dla;
endif;
?>
This is the code I’m trying to hack together. This returns a list of values for each field. Now I need to figure out how to add (sum) them together.
Any ideas?
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'pov_travel'
));
?>
<?php
if( $posts ):
$dla = 0;
?>
<?php foreach( $posts as $post ): ?>
<?php
$dla = get_field ('dla');
echo $dla;
?>
<?php endforeach; ?>
<?php endif; ?>
Disregard,
I removed function send_email( $pov_id ) {}
and it works fine.
This is the value in walking away from the code and coming back later.
James,
I’m out of troubleshooting ideas, I just submitted the support ticket.
Mission complete, had to add.
'new_post' => array(
'post_type' => 'pov_travel',
'post_status' => 'publish'),
Here is my template code:
<?php
/**
*
Template Name: test form Full Width
*
* Description: A page template without the left or right columns
* @package flat_responsive
* @since 1.0.0
*/
acf_form_head();
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php //the_title(); ?></h1>
<?php
if(isset($_GET['updated'])){
if($_GET['updated'] == 'true'){
echo '<p style="color:green;font-weight:bold">The file details have been submitted.</p>';
}
}
?>
<?php
acf_form(array(
'id' => 'POV-Travel',
'post_id' => 'new_post',
'field_groups' => array(431),
'submit_value' => 'Submit',
));
?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
Here is my functions code (I’m assuming we’re about the functions.php in my theme):
///////////////////////////////////////////////
// Form Processor
///////////////////////////////////////////////
function pre_save_post( $post_id ) {
// stop function if not a new post
if( $post_id !== 'new_post' ) {
return $post_id;
}
// vars
$title = $_POST['fields']['field_577eeca76c4be'];
$dla = $_POST['fields']['field_577d8805fbf95'];
$miles = $_POST['fields']['field_577d9ddb09284'];
$service_member = $_POST['fields']['field_577d9e4e61f79'];
$deps_over_12 = $_POST['fields']['field_577da50b58664'];
$deps_under_12 = $_POST['fields']['field_577da57183151'];
$malt = $_POST['fields']['field_577da5d6049df'];
// Create a new post
$post = array(
'post_status' => 'publish',
'post_type' => 'pov_travel',
'post_title' => $title,
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
The form renders on the frontend OK here: http://www.pcscalculator.com/mixed-mode/
When I try to submit, the frontend appears to work but nothing is submitted to the custom post type.
I can submit to this CPT from the backend with no problems. I have taken code snippets from https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/ and Leanne’s form https://support.advancedcustomfields.com/forums/topic/displaying-form-on-front-end-location-rules-issues/.
My field group is set to only appear on post type pov travel.
I’m running ACF 5 Pro.
I have a field group with 6 fields My acf_form code looks like this.
<?php acf_form(array(
'id' => 'POV-Travel',
//'post_id' => 'new_post',
'post_type' => 'pov_travel',
'new_post' => array(5),
'submit_value' => 'Submit'
)); ?>
So this will save the values from my POV-Travel field group to a new post type of pov_travel correct?
I’m trying to make sure the frontend piece is correct before I move on to the form processing code in the functions file.
The one problem I have seems to be if I uncomment the post_id line it breaks the form.
Any ideas?
Thanks for your help, I do appreciate it.
So 'id' => 'Add files form',
is the name of the Field group that makes up the form?
Leanne,
Do you mind sharing your functional code, I’m fumbling my way through a similar process.
Thanks in Advance.
Good information John, I appreciate it.
I think as long as I can get every calculator submission by any user in the database and be able to run some queries on that data, that would accomplish what I need.
It sounds like using a CPT would do that.
So the CPT would allow my users to have access to calculator submissions going forward? And, each users submissions would only be viewable by that user, not all the other members correct?
I just upgraded to the Pro version and it seems to work now. Not sure what the differences are though.
Interesting.
This is what I see in Chrome :
This is what I see in IE:
Thanks, James.
I’ll have a look at the docs and see what I can come up with.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.