Support

Account

Home Forums General Issues Display 2 seperate forms depending on query result

Solved

Display 2 seperate forms depending on query result

  • Hi, im absolutely loving ACF, and after 2 days of messing around trying to get the post title to update, ive sussed it and have to move the form head into my AVADA header.php file thatI copied to the child theme.

    All is updating correctly now.

    Im currently trying to display a form to a user that ID matched the author ID of a single post pulled…

    Then, if no ID matches author ID, display the acf form to create a new post.
    (Driver Profiles)

    Form displays for matching ID perfectly, but the new post form only displays the title (which im fine with) but does not create the post when submitted.

    <?php
    $args = array(
    	'post_type' 		=> 		'driver',
    	'author'        	=>  	$current_user->ID,
    	'orderby'       	=>  	'post_date',
    	'order'         	=>  	'ASC',
    	'posts_per_page' 	=> 		1
    );
    $post_query = new WP_Query($args);
    if($post_query->have_posts() ) {
    	while($post_query->have_posts() ) {
    		$post_query->the_post();
    		echo('We Found A Profile!'); // Debug
    		acf_form(array(
    		'post_id'       => get_the_ID(),
            'post_title'    => true,
            'post_content'  => false,
    		'uploader' => 'basic',
            'submit_value'  => __('Update Profile'),
    		'updated_message' => __("Profile updated", 'acf')
    		));
    	}
    } else {
    	echo ('No Profile Found, Please Create Your Profile Below'); // Debug
    	acf_form(array(
    		'post_id'       => 'new_post',
            'post_title'    => true,
            'post_content'  => false,
    		'uploader' => 'basic',
            'submit_value'  => __('Create Profile'),
    		'updated_message' => __("Profile Created", 'acf')
    		));
    };

    Could anyone spot any issue in my code at all?

  • My apologies, ive found the issue..

    
    'new_post'      => array(
    'post_type'     => 'driver',
    'post_status'   => 'publish'
    )
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.