Support

Account

Home Forums Front-end Issues get_field() with an id of new_data

Solving

get_field() with an id of new_data

  • Hi!

    I happened upon this as I was trying to fix a bug in my code and now it is really bothering me.

    If I have a field called ‘data’ and I type get_field(‘data’, ‘new_data’) it returns results. They are results which I can’t find in the admin section for the post type or searching the database in the wp_posts table or wp_postmeta.

    I have been creating posts from the front end and it seems possible a post has been created with a wonky ID but I don’t know how to find it to delete it…

    Any ideas where this data could be coming from?

    Thank you!

    James

  • What results is it returning? var_dump(get_field('data', 'new_data'));

    Since ‘new_data’ is being set as the post ID then from what I can figure out that is causing ACF to consider it a values that’s stored in the options table and getting the value for ‘new_data_data’.

    The question is, why are you using ‘new_data’ as the post id in get_field()?

  • Hi John, thanks for the reply.

    It returns a field for a post which I can’t find.

    Your question as to why I am doing it is very valid. I am setting a post ID (for a different post to the current one) as a variable and due to a bug in my code, it got set to ‘new_data’ instead of the proper ID. So I wouldn’t have known about it if I hadn’t written bad code

    It is totally avoidable, it is just irritating me as to why it is happening.

    James

  • Look in your wp_options table. Like I said above. I think it getting a values stored with the option name new_data_data, or at least that’s the best I can work out. ACF is assuming that the post ID is for a taxonomy term… I think.

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

The topic ‘get_field() with an id of new_data’ is closed to new replies.