Home Forums General Issues Accessing ACF field in WP_POST object / syntax


Accessing ACF field in WP_POST object / syntax

  • Hi there,

    I have a feed that takes a parameter

    $url = ‘’ . $ticker . ”;

    I need $ticker to be generated dynamically, because many stocks need to be displayed at the same time. To combat this. I created a CPT for companies. In companies, I created an ACF called ‘stock_ticker’.

    $query= new WP_Query(array(
    	'post_type'=>'companies', // your post type name
    	'posts_per_page' => -1, // post per page
    	'nopaging' => true,
    	'post_status' => 'publish',
    	'orderby' => 'menu_order title',
    	'order' => 'ASC',
    	// 'meta_key'      => 'bekeruljon_a_scrollerbe',
    	// 'meta_value'    => '1'
    $elements = $query->posts;
    foreach ( $elements as $index => $element ) {
    // $ticker = $element->post_title; // This works, but the title is not what I need
    $ticker = get_field('feed_id'); //  This is something that I would need, but I'm guessing I'm accessing it the wrong way.

    Any help is appreciated!

  • Managed to access date like so:

    $tickerid = $element->ID;
    $ticker = get_field(‘feed_id’, $tickerid );

Viewing 2 posts - 1 through 2 (of 2 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.