Support

Account

Forum Replies Created

  • Although it doesn’t particularly solve my problem as I wanted I guess adding the wp_delete_post($post_id) under failed conditionals will get rid of the empty posts, if otherwise, someone can correct me on that. Should I also add it in the condition that checks if $_POST['acf'] is empty before the return?

  • Thanks for the help, yes, its a front end form. Is there a hook that triggers before the post is inserted into the database?

  • EDIT: Actually what ended up happening was as I was changing some varaibles I misspelled one of them.

    After looking over everything it seems that my get_posts is not returning anything in the array and is NULL.

    <?php
    $teamLeaders = get_posts(array(
                    'post_type' => 'mro_volunteer',
                    'meta_query' => array(
                      array(
                        'key' => 'assigned_project', // name of custom field
                        'value' => '"' . get_the_ID() . '"', // matches exaclty
                        'compare' => 'LIKE'
                      )
                    )
                  ));
    ?>

    This is the correct post type and correct key, I checked the volunteers that are published and they all have the project in question assigned to them through the relationship field. I’m not sure why it can’t query them. It’s limited to only one if that makes any difference.

  • Thanks, after looking over a few more documents and other examples I was able to figure it out! Really great plugin, makes application creation very easy for me.

  • So if I’m understanding this hook correctly I’d be able to do something like this:

    <?php
    
    function my_acf_save_post( $project_id ) {
        
        // bail early if no ACF data
        if( empty($_POST['acf']) ) {
            
            return;
            
        }
    
       //obtain the current page's post ID
    	$project_id = get_the_ID();
        
        
        // array of field values
        $fields = $_POST['acf'];
    
        // specific field value
        $field = $_POST['acf']['assigned_project'];
        
    }
    
    // run before ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 1);
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
    ?>

    And $project_id would be stored in the ‘assigned_project’ acf field?

Viewing 5 posts - 1 through 5 (of 5 total)