• Resolved jdearana

    (@jdearana)


    Hello, I have checked the metakeys on the CP, and they appear on the JSON, but all of them are NULL, but the have values.

    Can someone help me?

    Thanks.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @jdearana,

    Which endpoint are you using?

    Let me know,
    Kevin.

    Thread Starter jdearana

    (@jdearana)

    Hi, thanks for answer so quickly.

    I create a custom endpoint called “articulos” and checked all the meta keys.

    https://postimg.org/image/9sb3g73l3f/

    And here is the link

    http://devecocesta.com.s116-126.furanet.com/wp-json/wp/v2/articulos

    I have to say that I haven’t created the page, the custom type or the custom fields, they were built by someone who isn’t in the company now, so I’m trying to figure what kind of fields an types built, because there is another custom type, where I have added a custom field, “numeroprueba” and is working:

    Hope you can help me, thanks.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @jdearana,

    Are you able to add a new meta field to articulos just to see if it works?

    Also, could you look into the database at a single articulos' post meta fields? Is the data clean? Are they saved consistently?

    You could also try some of our filters:

    The filter wp_rest_api_controller_api_property_value will allow you to hook into the value of each meta field. You could use this filter for testing (try echo’ing out some values, or returning a test string). The filter has three arguments: the value of the post meta field, the ID of the post, and the name of the field. Let me know if you need any more information on this filter.

    I am not sure what’s going on so any ideas as to what’s different between your newly-created CPT and the articulos CPT would help!

    Cheers,
    Kevin.

    Thread Starter jdearana

    (@jdearana)

    Sorry for the delay, I found the solution, in every custom field that was not working, I just wrote a Custom Meta Key, can be the same as the Meta Key, but I have to enter a name and save.

    Everything works. 🙂

    Hi,

    I have used this plugins for one of custom post of wp car manager.

    In which i am getting same issue of postmeta data show null, I had save all custom meta key against meta key which are shown for this custom post but when i call through api it’s not inserting any postmeta data for this custom post and return all postmeta data as null.

    Could you help me how to send postmeta data through rest api and how to resolve this issue ?

    Thanks in advanced

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @niteshvaghani,

    Which endpoint are you hitting? Would you mind sending me the URL you’re going to?

    Thanks,
    Kevin.

    Hi,

    I am hitting to wpcm_vehicle endpoint.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @niteshvaghani,

    I am not sure what’s going. There are a few things to try though.

    1. Do you have any other custom post types? Can you enable them using our plugin and check if their post meta is accessible via the API?

    2. How are you making this custom post type? Are you using a plugin? Are there any REST API settings coming from the plugin? It may be that our plugin is conflicting with another one.

    3. You can try using the filter I mentioned above. I will copy that paragraph here.
    The filter wp_rest_api_controller_api_property_value will allow you to hook into the value of each meta field. You could use this filter for testing (try echo’ing out some values, or returning a test string). The filter has three arguments: the value of the post meta field, the ID of the post, and the name of the field. Let me know if you need any more information on this filter.

    Sorry for the delay it’s been a busy day.

    Cheers,
    Kevin.

    Hi,

    Thanks of quick response.

    1. I didn’t enabled other CPT. I had just enable wpcm_vehicle CPT. I will check with other CPT enabled and it’s post type. I will keep you update on this

    2. I have used plugins JSON API – Custom fields support for the create_post method, JWT Authentication for WP-API, WP Rest Api Controller, WP REST API – Meta Endpoints (Just for testing installed yesterday ), WP REST API Controller, WP REST API Custom Fields, Advanced Custom Fields

    3. I have echo out this wp_rest_api_controller_api_property_value and it’s give return value 1 and if i print field variable it’s give meta key name but didn’t received meta value.

    Hope above thing clear out picture to you

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @niteshvaghani,

    So let’s focus on your filter function using the wp_rest_api_controller_api_property_value.

    For testing, that function should look something like:

    add_filter( 'wp_rest_api_controller_api_property_value', 'testing_rest_api_controller', 10, 3 );
    
    function testing_rest_api_controller( $meta_value, $post_id, $post_meta_name ) {
        var_dump( $meta_value );
        var_dump( $post_id );
        var_dump( $post_meta_name );
    }

    Now let’s take one of your meta field’s where you know what the value should be and add a get_post_meta() call for that specific meta field’s value. I’ve added this line in the following function. Replace 'example_meta_key_name' with the meta key you’d like to test with. Does this return the correct value? Is the value returned from this call different than the value returned as the first parameter (meta_value)?

    add_filter( 'wp_rest_api_controller_api_property_value', 'testing_rest_api_controller', 10, 3 );
    
    function testing_rest_api_controller( $meta_value, $post_id, $post_meta_name ) {
        var_dump( $meta_value );
        var_dump( $post_id );
        var_dump( $post_meta_name );
        var_dump( get_post_meta( $post_id, 'example_meta_key_name', true ) );
    }

    Let me know if that approach makes sense and what the results are.

    All the best,
    Kevin.

    Hi @yikesitskevin

    I’m facing the same problem.

    I’m using the Toolset Types plugin to create:

    • Custom Post Types
    • Custom Field Types

    I use your plugin to return the Custom Field Types in the WP REST API. When I leave the default value for the Meta Key the values return “null”. After changing the value e.g. wpcf_video to cf_video, the value returned is correct.

    FYI I’m not creating themes in WordPress, I only use it as an Headless CMS in combination with a front-end language of my choice.

    • This reply was modified 8 years, 1 month ago by yclaes.
    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @yclaes,

    Do you know if the original meta keys that are causing problems have dashes in them?

    Also, is it a problem if you’re required to rename the meta fields?

    Let me know.

    Cheers,
    Kevin.

    Hi @yikesitskevin

    The original Meta Keys have values like (without any dashes):

    • video
    • email

    No, it’s not a problem at all. I’m happy that it works even if I have to change the Meta Key values.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Null meta keys’ is closed to new replies.