Home Forums General Issues Using ACF inside group in meta description not working


Using ACF inside group in meta description not working

  • Trying to call the value inside the head for a meta description so far without luck.
    I’m trying:

    <?php if (in_category("proyectos")) {

    $group = get_field('caracteristicas');
    $superficie = $group['superficie_o_potencia'];
    echo ($superficie);

    That echo returns “superficie” and should instead return the value of the acf..

  • If you are in the header then you are outside of “The Loop”. When you are outside of the loop you must provide ACF with the post ID of the post you want to get the value from because ACF cannot determine the correct post outside of the loop.

    If what you are looking for is on a single post object then you would use something like

    $queried_object = get_queried_object();
    $group = get_field('caracteristicas', $queried_object);
  • Thanks well I was just going to post and your were faster than me 😀 I made a very silly mistake: instead of this:
    $superficie = $group['superficie_o_potencia'];

    I should had been:
    $superficie = $group['superficie'];

    I’m afraid I was too quick assuming things..

    Nevertheless, I confirm using get_queried_object does work just fine as well, and may use it in the future, thank you so much!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.