Support

Account

Home Forums Front-end Issues Show select list with ACF field on CPT

Unread

Show select list with ACF field on CPT

  • Hi there, I need to show a dropdown list on the frontend that displays a list of all items entered into a text ACF field that is attached to a custom post type. I then display this using a shortcode. When selected, it redirects to the related CPT post.

    I’ve had this working showing the post_title but can’t get this working for an ACF field. I have tried changing the $recent[“post_title”] to the acf field but it didn’t work and I’m not really sure how to go about this.

    Any ideas? Thanks in advance for your help 🙂

    function awg_prime_dropdown() { 
    $string .= '<div class="select-menu"><select id="dropdown">
                <option  value="" selected>Select item<option>';
     
    $args = array( 'numberposts' => '-1', 'post_type' => 'custom_post_type', 'post_status' => 'publish' );
     
    $recent_posts = wp_get_recent_posts($args);
        foreach( $recent_posts as $recent ){
            $string .= '<option value="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</option> ';
        }
     
    $string .= '</select>
                <script type="text/javascript"> var urlmenu = document.getElementById( "dropdown" ); urlmenu.onchange = function() {
                window.open( this.options[ this.selectedIndex ].value, "_self" );
                };
                </script>';
     
    return $string;
    } 
    .... shortcode and redirect info here
    
Viewing 1 post (of 1 total)

The topic ‘Show select list with ACF field on CPT’ is closed to new replies.