skip to Main Content

database data

return array( get_post_meta(12785, 'attribute_settings', true));

or

return array( get_post_meta("12785", 'attribute_settings', true));

it returns [""] changing the key with another value, it returns the value in the database.

2

Answers


  1. Try this below code.

    $attribute_settings = array();
    
    $attribute_settings[] = get_post_meta( 12785, 'attribute_settings', true );
    
    return $attribute_settings;
    
    Login or Signup to reply.
  2. You mention that if you change the key, you get the value you want. Looking at your screenshot, you’ve got duplicate keys for attribute_settings. How you got a duplicate key in there, I’m not sure (did you add them directly in phpMyAdmin? Using update_post_meta() will update the record if it exists)

    Now, I haven’t seen the case before where a duplicate post_id:meta_key pair exists, but I’d wager it’s returning at the NULL value since it’s first. Delete that entry and you should be good.

    Picture of the duplicate


    Documentation & Function Reference

    Function Linked Description
    update_post_meta() Updates a post meta field based on the given post ID.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search