Support

Account

Home Forums Backend Issues (wp-admin) Add acf field to post type AND to the quick edit screen

Solving

Add acf field to post type AND to the quick edit screen

  • Hi. I feel like I just wasted hours of coding. Hoping for some help. I added a true/false checkbox to my custom post type. Check the box to feature this post on the front page. It works fine. I even added a column on the post type admin screen so that you can clearly see which posts have been promoted to the front page with a ‘Yes’ or ‘No’ in the column.

    My problem is I would like to have that same checkbox available as a Quick Edit option, so that users do not have to open the full edit screen and go in and check the box and click ‘Save’ to feature a post on the front page. I’d like them to be able to edit that particular option quickly using Quick Edit AND also have the option to edit it from within the page edit screen when creating a new post.

    But it looks like I have to choose one or the other place for this checkbox? I can’t have them in both places and have them talk to each other? Either place works fine alone, either on the edit screen or in the quick edit area, but when I have both at the same time, they conflict.

    Is there a way to do this properly? Please help!

  • There is nothing built into ACF for quick edit. You need to build it yourself or try this plugin https://wordpress.org/plugins/acf-quickedit-fields/

  • Yes, I know there is nothing built into ACF for Quick Edit, which is why I already built it myself. So, that doesn’t answer my question. Can you read the question again, please?

  • I know this is a bit late but I just had this same issue I was trying to solve. I managed to get a working proof of concept by Frankensteining a number of different tutorials together. I have an ACF field on the custom post type page called ‘homepage_order’ that I can enter data in and if I go to the posts list page I can see that content in a custom column and update the content from the Quick Edit box of each post. I am not a proficient PHP coder so I’m sure there are glaring errors and my security checks are not all there (some of them are causing the update to fail) but hopefully this will help point you in the right direction. If anyone has any comments on how I can make this better, I would be most appreciative.

    
    //Adds the custom column to the exhibits posts list page
    add_filter( 'manage_exhibits_posts_columns', 'heard_filter_posts_columns' );
    function heard_filter_posts_columns( $columns ) {
      $columns['homepage_order'] = __( 'Current Exhibits Order', 'heard' );
      return $columns;
    }
    //Gets the data from the custom field populated in the exhibits post and adds it to the column
    add_action( 'manage_exhibits_posts_custom_column', 'heard_homepageorder_column', 10, 2);
    function heard_homepageorder_column( $column, $post_id ) {
      // Image column
      if ( 'homepage_order' === $column ) {
        echo get_post_meta( $post_id, 'homepage_order', true );
      }
    }
    //Creates a fillable field in the Quick Edit box
    add_action( 'quick_edit_custom_box', 'heard_custom_edit_box_pt', 10, 3 );
    function heard_custom_edit_box_pt( $column, $post_id ){
    
    if($column == 'homepage_order'){
        $html .= '<fieldset class="inline-edit-col-right ">';
            $html .= '<div class="inline-edit-group wp-clearfix">';
                $html .= '<label class="alignleft" for="homepage_order">Current Exhibits Order</label>';
                $html .= '<input type="text" name="homepage_order" id="homepage_order" value="" />';
            $html .= '</div>';
        $html .= '</fieldset>';    
    }
    
    echo $html;
    }
    //Saves any updates to the current exhibit order field in the Quick Edit box
    add_action( 'save_post_exhibits', 'heard_update_custom_quickedit_box' );
    function heard_update_custom_quickedit_box() {
      //There are currently limited security measures in place on this. The quick edit field won't update when I add all of them. Still working on this.    
      //Check user permissions- this works
    if ( 'page' == $_POST['homepage_order'] ) {
            if ( !current_user_can( 'edit_page', $post_id ) )
                return $post_id;
        }
        // save homepage_order updates in Exhibits- custom post type
        if( isset( $_POST['homepage_order'] )) { // where homepage_order is defined in the <input name="homepage_order">
            update_post_meta($_POST['post_ID'], 'homepage_order', $_POST['homepage_order']);
        }
        return; // finish the function call
    }
    
  • //Image column should be //Current Exhibits Order column. FYI.

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

You must be logged in to reply to this topic.

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.