Support

Account

Home Forums General Issues Using get_field with {{data.type}} variable as post id

Solving

Using get_field with {{data.type}} variable as post id

  • Hi there,

    The theme I’m using (Listify) has a template that displays the ID of each post using the {{data.id}} variable. When I try to use ‘ echo get_field(‘field_name’,'{{data.id}}’); ‘, nothing happens.

    When I do a regular echo ‘{{data.id}}’, the post id appears.

    How can I use such variables with the get_field function?

    Appreciate any input

  • Hey edmundcwm,

    I’m not familiar with the Listify theme, but that variable ( {{data.id}} ) looks like something from a templating language rather than a regular PHP variable. It’s probably converted to the ID after all the PHP work is done (including get_field ).

    WordPress has a function to get the ID that may be available to you in the template you are working on. Maybe give this a try:

    
    $post_id = get_the_ID();
    echo get_field( 'field_name', post_id );
    

    .. or post a bit more of your code so we can get a better sense of what’s going on!

    Hope this helps.

  • Hi edmundcwm,

    I know it’s been a while. But did you solve the issue?
    I’m having the same problem 🙁

  • Hey Infabula,

    I can’t remember if I had found the solution to the problem; it’s been 3 years ago 😄 Hope you will be able to solve it!

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

The topic ‘Using get_field with {{data.type}} variable as post id’ is closed to new replies.