OiO.lk Blog PHP ACF WordPress Map User To Custom Post Type
PHP

ACF WordPress Map User To Custom Post Type


I have created a series of text fields, a User field and a repeater field (with sub fields) which displays when I create a new post under the Custom Post type "deliveries" from the backend. I am wanting to attach the post type, to a specific user (Which I select from the User field dropdown)

From there, I am wanting to display the sub field repeater values (e.g. Repeater field data) from the post which a selected user is assigned to, on to the frontend of my website for the current logged in user. If there isn’t any posts assigned to a partciular, then a message would display e.g. "No deliveres found for your account".

add_shortcode('display_delivery_info', 'render_delivery_info');
function render_delivery_info() {

    $customer_delivery = wp_get_current_user();
    $customer_id_delivery = get_current_user_id();
    

if( have_rows('parcel_update_manager', 'user_', $customer_id_delivery ) ): ?>

    <ul>

    <?php while( have_rows('new_parcel_update', 'user_', $customer_id_delivery) ): the_row(); ?>

        <li><?php the_sub_field('delivery_status'); ?></li>

    <?php endwhile; ?>

    </ul>

<?php endif; 

}

At the moment, the above code isn’t returning any data from the fields I have created and I’m unsure to whether I’ve missed a vital step beforehand – Would I need to add an action to assign a user to the custom post type I have created, in order to display the relational data on to the frontend of my website (For my user to view when they are signed in?)

(I’m a newbie to ACF, so I’m currently just following the guidance on the Repeater Fields documentation, with trying to get this to work)

Thanks!



You need to sign in to view this answers

Exit mobile version