Forum Replies Created

Viewing 15 replies - 1 through 15 (of 24 total)
  • Hello slegg!

    You could use WP REST API Filter Fields plugin to do that and use it like “&fields=ID,title,author,bla bla” at the end of the endpoint to only get those values.

    Hello matheo972!

    As far as I see… https://www.site.fr/wp-admin/edit.php? >>>> post_type=tribe_events <<<<

    is a Post Type and not a category… post type are getting like this:

    yourwebsite.com/wp-json/posts?type=tribe_events

    and to get a Taxonomy, you must use: “filter[taxonomy]=your_taxonomy”

    example of full website with and without custom post and both using custom category:

    (with custom post type) yourwebsite.com/wp-json/posts?type=your_post_type&filter[taxonomy]=your_taxonomy

    (without custom post type) yourwebsite.com/wp-json/posts?filter[taxonomy]=your_taxonomy

    hope that helps you. (with v2 you must go to v2 plugin site… or add “/wp-json/wp/v2/” instead of just “/wp-json/” to my endpoints.

    Remember to replace “yourwebsite.com” with your actual website and “your_post_type” and “your_taxonomy” with the same logic.

    WordPress plugin updates always override every single file… It doesn’t ask you to keep some/any modify files.

    If you want to keep your changes, use FTP to upload the files and DON’T override your custom files (but you’ll need to check them anyway if something is needed for the new update… every single time)

    Other similar approach is to change the plugin folder name and manually “update” new files and keep your changes.

    You should always have a backup of your custom code for 3rd party plugins (and 1st party ones… any plugin that is not yours)

    Forum: Plugins
    In reply to: [WP REST API (WP API)] re

    Hello firas.

    You need to use it like this:

    your-url-goes-here.com/wp-json/posts?type=your-custom-post-type

    Change your-url-goes-here.com with your actual URL and your-custom-post-type with your post type.

    Example:

    amazingwebsite.com/wp-json/posts?type=coins (for example… this is a fake url, of course)

    Remember that always after /posts, /users, /media goes a “?” and the next endpoint filter goes with “&”… so, If you can to put the post type at last… goes like this:

    amazingwebsite.com/wp-json/posts?filter[s]=Hello!&type=coins

    Then, you search all “Hello!” inside custom post type: coins

    Hello @damienoneill2001

    You need to change the level permission for that… that would be the “10” at the end. Try using 12, 2, 4 or similar. 2 works for me in some cases.

    Thread Starter mkiisoft

    (@mkiisoft)

    If someone need it:

    user Basic Auth (or any other Auth), then:

    my-domain.com/wp-json/posts/IDofPost/meta/MetaID

    the use value pair to upload the value of it. Normally, having the ID of the Meta, you only need to pass: value=Example

    if you want to use full endpoint is:

    my-domain.com/wp-json/posts/IDofPost/meta/MetaID?data[value]=Example

    PS: Change IDofPost and MetaID for the values you need. Check your meta response to know which one you need to edit.

    Thread Starter mkiisoft

    (@mkiisoft)

    BTW… how can I make a POST request to a custom meta key?

    mydomain.com/wp-json/users/1?data[my_meta_key]=2500

    is not working… any hint for that?

    EDIT: I also try https://wp-api.org/#posts_create-meta-for-a-post without any luck. Is a lack of info in that with the endpoint

    Should be something like this: my-domain.com/wp-json/posts/1223/meta?data[my_meta_key]=2500

    of what???

    PS: Every other “native” meta key is working with POST request and I can edit it.

    Thread Starter mkiisoft

    (@mkiisoft)

    Never mind… use this:

    add_filter( ‘json_prepare_user’, ‘add_user_metadata’, 10, 3 );

    function add_user_metadata( $user_fields, $user, $context ) {
    add_author_meta_field( $user_fields, ‘user_coins’ );
    return $user_fields;
    }

    function add_author_meta_field( &$user_fields, $field ) {
    if ( $meta = get_the_author_meta( $field, $user_fields[‘ID’] ) ) {
    $user_fields[ $field ] = $meta;
    }
    }

    and “add_author_meta_field” for every meta key you need.

    Hope that helps someone else!

    Hello mnavaidd.

    Quotation marks are reserved for meta keys and values… normally, quotes ‘ll look like this \” or &#34 or u0022 (and maybe others). You have the full list here: https://www.fileformat.info/info/unicode/char/0022/index.htm

    Also, inside html tags (for your content), quotes are also reserved and can be “normally used”… and it’ll look like the ones I’ve already told you.

    Most languages and mobile OS ‘ll understand the \” and &#34… maybe you need a replace string for u0022

    When you parse a Json Response… the json parser removes all quotes from the meta keys and values and only get the info inside of each.

    Hello igiaki! Please, check your meta info every time you check a category name.

    Your category ID 55 is “artisti” and the meta you need to check is either “artisti” or 54 (again, check your meta info).

    The endpoint you are looking for is this one:

    vision-club.it/wp-json/posts?filter[category_name]=artisti&filter[post_per_page]=10&page=1

    Hope that helps ??

    PS: add “https://www.&#8221; normally, wp forum remove the [] brackets if you add the first part of the url.

    Then, use this next snippet over fuctions.php (of your theme) or download the plugin “Code Snippets” (save and activate to make it work):

    function remove_extra_data( $data, $post, $context ) {
    // We only want to modify the ‘view’ context, for reading posts
    if ( $context !== ‘view’ || is_wp_error( $data ) ) {
    return $data;
    }

    // Here, we unset any data we don’t want to see on the front end:

    unset( $data[‘meta’] );

    // To unset tree nested specific data, you need to declare the
    // “parent” key and then the actual key, for example:
    // unset( $data[‘author’][‘description’] );
    // unset( $data[‘author’][‘URL’] );
    // that’ll only unset description and URL inside author.
    // continue unsetting whatever other fields you want

    return $data;
    }

    add_filter( ‘json_prepare_post’, ‘remove_extra_data’, 12, 3 );

    Tell me if that works! ??

    PS: If you want to build an app… meta info is a good for you. You can actually check it from the json response and not saving that data locally on you app. If the meta URL changes, you’ll have to update the entire app.

    Sup, Dave! I’m also using ACF and this is the best way to add meta keys from it to the json response:

    function custom_meta_name( $post_response, $post, $context ) {

    $valueone = get_field( “name-value-one”, $post[‘ID’] );
    $valuetwo = get_field( “name-value-two”, $post[‘ID’] );

    $post_response[value_one] = $valueone;
    $post_response[value_two] = $valuetwo;

    return $post_response;
    }
    add_filter( ‘json_prepare_post’, ‘custom_meta_name’, 10, 3 );

    INFO: name-value-one is your actual key from ACF, check the names you use for it and [value_one] is any name you want to “print” on the Json response

    Add it on functions.php or with “Code Snippets” plugin. Cheers!

    Hello mnavaidd!

    The endpoint to get the categories and category names are not inside “post”… are inside “taxonomies”, like this:

    your-url.com/wp-json/taxonomies/category/terms

    Then, to get post of that category:

    your-url.com/wp-json/posts?filter[category_name]=CategoryName (replace CategoryName with the actual slug of that category).

    The specific category name is inside this tree:

    terms > category (this one is an array) > name (this is the actual category name)

    Inside category, you can reach the meta info. Then: meta > links > self

    your-url.com/wp-json/taxonomies/category/terms/7

    The problem is that you’re taking “category” as an object and, remember, is an array. Post could/can have more than 1 category.

    Hello drspencer! Don’t know if that’s possible… or easily possible.

    Try this:

    your-url.com/wp-json/media?filter[s]=mp3 or your-url.com/wp-json/media?filter[s]=%2Emp3

    Also, a really advance search ‘ll need more plugins:

    Step 1: Install WordPress 4.3 beta
    Step 2: Install WP REST API (WP API) v2
    Step 3: Install SearchWP plugin 2.6+
    Step 4: Install SearchWP API plugin

    After ALL that you should have an amazing query filter power… a few examples are here:

    https://calderawp.com/doc/searchwp-api-queries/

    Hello prajaktadhanke! To get the content of an specific user, you must know the user ID. To get all users and users ID, use this endpoint: your-url-goes-here.com/wp-json/users

    One you know the user ID, simple use this:

    your-url-goes-here.com/wp-json/posts?filter[author]=1

    ID: 1 normally is the “admin”. If “co-author josh” (for example) is ID: 2… then, use filter[author]=2 at the end of your URL.

    Ones you have that, install “WP REST API Filter Fields” plugin and add this endpoint: &fields=ID,title,content,featured_image,date

    That will only shows you those values with a clean small json response.

    PS: Please, replace “your-url-goes-here.com” with your actual URL

Viewing 15 replies - 1 through 15 (of 24 total)