Cannot get ACF from custom post type postDetecting request type in PHP (GET, POST, PUT or DELETE)How do I get a YouTube video thumbnail from the YouTube API?Post Objects within repeater field (WordPress ACF)ACF relationship fields - get_field values from other post typeNested ACF JSON data in WP REST API with custom post typeACF custom field. Get field inside action within functions.phpSorting query of custom posts by ACF Date Picker not working properly?Mix post-object with sub fields in ACFPHP - creating a new array through nested arrays while creating a post/image relationshipUpdate available posts in all ACF Post Object fields on change (Wordpress/Advanced Custom Fields)

Is Dumbledore a human lie detector?

How (un)safe is it to ride barefoot?

Do Veracrypt encrypted volumes have any kind of brute force protection?

Find all letter Combinations of a Phone Number

How to handle when PCs taste a potion that is actually poison?

As easy as Three, Two, One... How fast can you go from Five to Four?

Are the guests in Westworld forbidden to tell the hosts that they are robots?

If the pressure inside and outside a balloon balance, then why does air leave when it pops?

Should I list a completely different profession in my technical resume?

What does this line mean in Zelazny's "The Courts of Chaos"?

Who is "He that flies" in Lord of the Rings?

Course development: can I pay someone to make slides for the course?

How much web presence should I have?

Is it safe to dpkg --set-selections on a newer version of a distro?

Are regulatory compliance checks performed within the EU bloc?

How to show a "node near coord" even when it is out of bounds (with clip = true)?

How do I type a hyphen in iOS 12?

Oil draining out shortly after turbo hose detached/broke

How can you estimate a spike story?

Is Jesus the last Prophet?

Is it advisable to add a location heads-up when a scene changes in a novel?

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

Create a cube from identical 3D objects

In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?



Cannot get ACF from custom post type post


Detecting request type in PHP (GET, POST, PUT or DELETE)How do I get a YouTube video thumbnail from the YouTube API?Post Objects within repeater field (WordPress ACF)ACF relationship fields - get_field values from other post typeNested ACF JSON data in WP REST API with custom post typeACF custom field. Get field inside action within functions.phpSorting query of custom posts by ACF Date Picker not working properly?Mix post-object with sub fields in ACFPHP - creating a new array through nested arrays while creating a post/image relationshipUpdate available posts in all ACF Post Object fields on change (Wordpress/Advanced Custom Fields)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a custom post type called "members", which has an ACF field connected. I try to get the content of that field. But when I try, I only get the regular post object. Not the ACF fields connected.



Here is what i am trying, but only getting the post object.



`



$featuredmembers = get_field('featured_member');
global $post;

//$featuredmembers has a field named "featured". That's the field I want.


$posts = get_posts([
'post_type' => 'members',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title'
]);


foreach ($featuredmembers as $post)
print_r($post['featured']->ID);
echo get_field('featured');



`










share|improve this question




























    0















    I have a custom post type called "members", which has an ACF field connected. I try to get the content of that field. But when I try, I only get the regular post object. Not the ACF fields connected.



    Here is what i am trying, but only getting the post object.



    `



    $featuredmembers = get_field('featured_member');
    global $post;

    //$featuredmembers has a field named "featured". That's the field I want.


    $posts = get_posts([
    'post_type' => 'members',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'order' => 'ASC',
    'orderby' => 'title'
    ]);


    foreach ($featuredmembers as $post)
    print_r($post['featured']->ID);
    echo get_field('featured');



    `










    share|improve this question
























      0












      0








      0








      I have a custom post type called "members", which has an ACF field connected. I try to get the content of that field. But when I try, I only get the regular post object. Not the ACF fields connected.



      Here is what i am trying, but only getting the post object.



      `



      $featuredmembers = get_field('featured_member');
      global $post;

      //$featuredmembers has a field named "featured". That's the field I want.


      $posts = get_posts([
      'post_type' => 'members',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'order' => 'ASC',
      'orderby' => 'title'
      ]);


      foreach ($featuredmembers as $post)
      print_r($post['featured']->ID);
      echo get_field('featured');



      `










      share|improve this question














      I have a custom post type called "members", which has an ACF field connected. I try to get the content of that field. But when I try, I only get the regular post object. Not the ACF fields connected.



      Here is what i am trying, but only getting the post object.



      `



      $featuredmembers = get_field('featured_member');
      global $post;

      //$featuredmembers has a field named "featured". That's the field I want.


      $posts = get_posts([
      'post_type' => 'members',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'order' => 'ASC',
      'orderby' => 'title'
      ]);


      foreach ($featuredmembers as $post)
      print_r($post['featured']->ID);
      echo get_field('featured');



      `







      php wordpress advanced-custom-fields






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 22:55









      mathias5mathias5

      2918




      2918






















          3 Answers
          3






          active

          oldest

          votes


















          0














          Try passing the post id in the get_field / the_field call within the foreach loop:



          foreach ($featuredmembers as $post) 
          // the_field('featured', $post->ID);
          echo get_field('featured', $post->ID);



          If it's a repeater field you can use:



          foreach ($featuredmembers as $post) 
          the_repeater_field('featured', $post->ID);






          share|improve this answer

























          • Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

            – mathias5
            Mar 24 at 23:09











          • Have you tried the_repeater_field('featured', $post->ID); ?

            – giolliano sulit
            Mar 24 at 23:10











          • Yes, same. No result.

            – mathias5
            Mar 24 at 23:12











          • Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

            – mathias5
            Mar 24 at 23:23











          • Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

            – giolliano sulit
            Mar 24 at 23:36


















          0














          I think this might be down the foreach loops using a variable of $post. This will override the main $post variable of the page, and any get_field function calls after the foreach loop will be looking at the wrong post.



          Try renaming those variables to something other than $post






          share|improve this answer






























            0














            Have you tried using WP_Query to get access to the post_id?



            $args = array(
            'post_type' => 'members',
            'post_status' => 'publish',
            'posts_per_page' => -1,
            'order' => 'ASC',
            'orderby' => 'title'
            );

            $query = new WP_Query( $args );

            if( $query->have_posts() ) :
            while( $query->have_posts() ) :
            $current_post->the_post();
            $post_id = get_the_ID();
            $featured = esc_html(get_post_meta($post_id, 'featured_member', true));
            endwhile;

            wp_reset_postdata();

            else :
            esc_html_e( 'no members found', 'text-domain' );
            endif;





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329370%2fcannot-get-acf-from-custom-post-type-post%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Try passing the post id in the get_field / the_field call within the foreach loop:



              foreach ($featuredmembers as $post) 
              // the_field('featured', $post->ID);
              echo get_field('featured', $post->ID);



              If it's a repeater field you can use:



              foreach ($featuredmembers as $post) 
              the_repeater_field('featured', $post->ID);






              share|improve this answer

























              • Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

                – mathias5
                Mar 24 at 23:09











              • Have you tried the_repeater_field('featured', $post->ID); ?

                – giolliano sulit
                Mar 24 at 23:10











              • Yes, same. No result.

                – mathias5
                Mar 24 at 23:12











              • Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

                – mathias5
                Mar 24 at 23:23











              • Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

                – giolliano sulit
                Mar 24 at 23:36















              0














              Try passing the post id in the get_field / the_field call within the foreach loop:



              foreach ($featuredmembers as $post) 
              // the_field('featured', $post->ID);
              echo get_field('featured', $post->ID);



              If it's a repeater field you can use:



              foreach ($featuredmembers as $post) 
              the_repeater_field('featured', $post->ID);






              share|improve this answer

























              • Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

                – mathias5
                Mar 24 at 23:09











              • Have you tried the_repeater_field('featured', $post->ID); ?

                – giolliano sulit
                Mar 24 at 23:10











              • Yes, same. No result.

                – mathias5
                Mar 24 at 23:12











              • Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

                – mathias5
                Mar 24 at 23:23











              • Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

                – giolliano sulit
                Mar 24 at 23:36













              0












              0








              0







              Try passing the post id in the get_field / the_field call within the foreach loop:



              foreach ($featuredmembers as $post) 
              // the_field('featured', $post->ID);
              echo get_field('featured', $post->ID);



              If it's a repeater field you can use:



              foreach ($featuredmembers as $post) 
              the_repeater_field('featured', $post->ID);






              share|improve this answer















              Try passing the post id in the get_field / the_field call within the foreach loop:



              foreach ($featuredmembers as $post) 
              // the_field('featured', $post->ID);
              echo get_field('featured', $post->ID);



              If it's a repeater field you can use:



              foreach ($featuredmembers as $post) 
              the_repeater_field('featured', $post->ID);







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 24 at 23:14

























              answered Mar 24 at 23:05









              giolliano sulitgiolliano sulit

              8271611




              8271611












              • Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

                – mathias5
                Mar 24 at 23:09











              • Have you tried the_repeater_field('featured', $post->ID); ?

                – giolliano sulit
                Mar 24 at 23:10











              • Yes, same. No result.

                – mathias5
                Mar 24 at 23:12











              • Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

                – mathias5
                Mar 24 at 23:23











              • Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

                – giolliano sulit
                Mar 24 at 23:36

















              • Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

                – mathias5
                Mar 24 at 23:09











              • Have you tried the_repeater_field('featured', $post->ID); ?

                – giolliano sulit
                Mar 24 at 23:10











              • Yes, same. No result.

                – mathias5
                Mar 24 at 23:12











              • Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

                – mathias5
                Mar 24 at 23:23











              • Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

                – giolliano sulit
                Mar 24 at 23:36
















              Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

              – mathias5
              Mar 24 at 23:09





              Hi! I have actually tried that, since thats how i usually do it. But it wont work. I get nothing. Its a repeater field if that makes sense.

              – mathias5
              Mar 24 at 23:09













              Have you tried the_repeater_field('featured', $post->ID); ?

              – giolliano sulit
              Mar 24 at 23:10





              Have you tried the_repeater_field('featured', $post->ID); ?

              – giolliano sulit
              Mar 24 at 23:10













              Yes, same. No result.

              – mathias5
              Mar 24 at 23:12





              Yes, same. No result.

              – mathias5
              Mar 24 at 23:12













              Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

              – mathias5
              Mar 24 at 23:23





              Only thing that i get to work is to get the post. Like: $post['featured']. But i don not get its ACF fields.

              – mathias5
              Mar 24 at 23:23













              Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

              – giolliano sulit
              Mar 24 at 23:36





              Oh, where are you calling get_post? you might already be inside a wp_query. If so try call it after the query

              – giolliano sulit
              Mar 24 at 23:36













              0














              I think this might be down the foreach loops using a variable of $post. This will override the main $post variable of the page, and any get_field function calls after the foreach loop will be looking at the wrong post.



              Try renaming those variables to something other than $post






              share|improve this answer



























                0














                I think this might be down the foreach loops using a variable of $post. This will override the main $post variable of the page, and any get_field function calls after the foreach loop will be looking at the wrong post.



                Try renaming those variables to something other than $post






                share|improve this answer

























                  0












                  0








                  0







                  I think this might be down the foreach loops using a variable of $post. This will override the main $post variable of the page, and any get_field function calls after the foreach loop will be looking at the wrong post.



                  Try renaming those variables to something other than $post






                  share|improve this answer













                  I think this might be down the foreach loops using a variable of $post. This will override the main $post variable of the page, and any get_field function calls after the foreach loop will be looking at the wrong post.



                  Try renaming those variables to something other than $post







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 1:25









                  Luke TubbyLuke Tubby

                  593




                  593





















                      0














                      Have you tried using WP_Query to get access to the post_id?



                      $args = array(
                      'post_type' => 'members',
                      'post_status' => 'publish',
                      'posts_per_page' => -1,
                      'order' => 'ASC',
                      'orderby' => 'title'
                      );

                      $query = new WP_Query( $args );

                      if( $query->have_posts() ) :
                      while( $query->have_posts() ) :
                      $current_post->the_post();
                      $post_id = get_the_ID();
                      $featured = esc_html(get_post_meta($post_id, 'featured_member', true));
                      endwhile;

                      wp_reset_postdata();

                      else :
                      esc_html_e( 'no members found', 'text-domain' );
                      endif;





                      share|improve this answer



























                        0














                        Have you tried using WP_Query to get access to the post_id?



                        $args = array(
                        'post_type' => 'members',
                        'post_status' => 'publish',
                        'posts_per_page' => -1,
                        'order' => 'ASC',
                        'orderby' => 'title'
                        );

                        $query = new WP_Query( $args );

                        if( $query->have_posts() ) :
                        while( $query->have_posts() ) :
                        $current_post->the_post();
                        $post_id = get_the_ID();
                        $featured = esc_html(get_post_meta($post_id, 'featured_member', true));
                        endwhile;

                        wp_reset_postdata();

                        else :
                        esc_html_e( 'no members found', 'text-domain' );
                        endif;





                        share|improve this answer

























                          0












                          0








                          0







                          Have you tried using WP_Query to get access to the post_id?



                          $args = array(
                          'post_type' => 'members',
                          'post_status' => 'publish',
                          'posts_per_page' => -1,
                          'order' => 'ASC',
                          'orderby' => 'title'
                          );

                          $query = new WP_Query( $args );

                          if( $query->have_posts() ) :
                          while( $query->have_posts() ) :
                          $current_post->the_post();
                          $post_id = get_the_ID();
                          $featured = esc_html(get_post_meta($post_id, 'featured_member', true));
                          endwhile;

                          wp_reset_postdata();

                          else :
                          esc_html_e( 'no members found', 'text-domain' );
                          endif;





                          share|improve this answer













                          Have you tried using WP_Query to get access to the post_id?



                          $args = array(
                          'post_type' => 'members',
                          'post_status' => 'publish',
                          'posts_per_page' => -1,
                          'order' => 'ASC',
                          'orderby' => 'title'
                          );

                          $query = new WP_Query( $args );

                          if( $query->have_posts() ) :
                          while( $query->have_posts() ) :
                          $current_post->the_post();
                          $post_id = get_the_ID();
                          $featured = esc_html(get_post_meta($post_id, 'featured_member', true));
                          endwhile;

                          wp_reset_postdata();

                          else :
                          esc_html_e( 'no members found', 'text-domain' );
                          endif;






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 25 at 15:31









                          KaltiKalti

                          326




                          326



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329370%2fcannot-get-acf-from-custom-post-type-post%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현