Home Forums Front-end Issues Querying all posts send by non-login user to a specific author Reply To: Querying all posts send by non-login user to a specific author

  • This is the codes i wrote for front end submission form that appears in all the companies single.php page for the clients

    ‘post_id’ => ‘new_post’,
    ‘post_title’ => true,

    ‘post_content’ => false,
    ‘field_groups’ => array(648),
    ‘form’ => true,
    ‘new_post’ => array(
    ‘post_status’ => ‘publish’,

    ‘submit_value’ => ‘Submit’,
    ‘updated_message’ => ‘Thanks, you have successfully submitted your posts ‘
    ));endwhile ?>

    //This is the code for querrying all messages sent by clients for a specific company’s dashboard page(dasboard.php) the company admin login.
    $user = get_current_user_id();
    $args = array(

    $query = new WP_Query($args);?>

    <?php while ($query ->have_posts() ) : $query ->the_post(); ?>

    <p><?php the_field(‘name’);?></p>
    <p><?php the_field(‘subject’);?></p>

    <?php endwhile; wp_reset_query();// end of the loop. ?>

    // This is the codes for updating client of the newly created messages with the companies ID. (functions.php)

    function my_acf_save_post_change_author( $post_id ) {

    // Get the company’s user ID (depends on how you set it)
    $company_id = 2;

    // Only do this if posted from front end
    if( !is_admin() ){

    // Get the post object
    $the_post = get_post($post_id);

    // Check the post type
    if( $the_post->post_type == ‘message’ ){

    // Set the data you want to update
    $my_post = array(
    ‘ID’ => $post_id,
    ‘post_author’ => $company_id,

    // Remove action to avoid infinite loop
    remove_action(‘acf/save_post’, ‘my_acf_save_post_change_author’, 20);

    // Update the post into the database
    wp_update_post( $my_post );

    // Add the action back
    add_action(‘acf/save_post’, ‘my_acf_save_post_change_author’, 20);




    // run after ACF saves the $_POST[‘acf’] data
    add_action(‘acf/save_post’, ‘my_acf_save_post_change_author’, 20);