customization – Custom Menu (only showing direct cildren) ACF not showing

Question

I have working codes for both problems, but can’t combine them.

following code adds the acf in a standard menu:

function my_wp_nav_menu_objects( $items, $args ) {
    
    // loop
    foreach( $items as &$item ) {
        
        // vars
        $sub = get_field('subhead', $item);
        
        
        // append icon
        if( $sub ) {
            
            $item->title .= ' <span>'.$sub.'</span>';
            
        }
        
    }
    
    
    // return
    return $items;
    
}

for my special menu I use

function wpb_list_child_pages() { 
    global $post; 
    if ( is_page() && $post->post_parent ) {
        $parent = get_post($post->post_parent);
        if ($parent->post_parent) {
            $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=" . $post->ID . "&echo=0&depth=1' );
        } else {
            $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=" . $post->ID . "&echo=0&depth=1' );
        }
    } else {
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=" . $post->ID . "&echo=0&depth=1' );
    }
    if ( $childpages ) {
        $string = '<ul>' . str_replace('</a>',' <span>'.$sub.'</span> Custom Text</a>', $childpages) . '</ul>';
    }
    return $string;
}
add_shortcode('wpb_childpages', 'wpb_list_child_pages');

Where I have “Custom Text” I want the value of the ACF.

Maybe my problem would be solved if the items were menu_items and not page_items but right now I’m at a loss.

Appreciate any help

Right now the ACF is assigned to the menu item, if there is a solution where the ACF is assigned to the page, that would be fine, too.

0
Thomas 1 month 2023-04-19T10:41:44-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse