Support

Account

Home Forums Add-ons Repeater Field Show post object's fields in backend…

Solved

Show post object's fields in backend…

  • Hi There.
    I have a post object field inside a repeater table.
    In the back end I would like to be able to select the post object from the post object field and then for it to display the field data directly below my selection.
    I think this is possible as I’ve seen it on another development however I was wondering if someone can tell me how to do it?
    thanks
    Gordon

  • Hi @bigfootnetworks

    It depends on how you want it to show up. If you want the data to show up when you change the post object, you need to use AJAX.

    If you don’t need the data to show up right away, you can use this code:

    function action_function_name( $field ) {
    
    	if( $field['value'] ){
            $thepost = get_post($field['value']);
            echo '<p>'. $thepost->post_title .'</p>';
        }
    
    }
    add_action( 'acf/render_field/type=post_object', 'action_function_name', 20, 1 );

    That code will show the post title after you saved the post/page that has the post object field.

    If you need further customization, I’m afraid you would need to hire a developer to help you out with it, and I’d recommend looking for one on https://studio.envato.com/ or https://www.upwork.com/.

    I hope this helps 🙂

  • I think that might do it for now.
    Can you confirm the location I would place this code please?
    I’m pretty new to this.
    Thanks

  • Hi @bigfootnetworks

    You can put that code in your functions.php file in your theme. But if you have a child theme, that would be better. Also, please take a look at this page to learn more about WordPress post object: https://codex.wordpress.org/Class_Reference/WP_Post.

    I hope this helps 🙂

  • @acf-support

    Hello,

    Thank you for the code, it works well for me. Is it possible please to show the post id instead of the post title? Or maybe both

    My goal is to let my authors search for a post by name and the result is the title and the id (in the backend)

    Using “Objet Article” field

    Screenshot : https://prnt.sc/uy985f

    Please advise,

    Thank you

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

The topic ‘Show post object's fields in backend…’ is closed to new replies.