Forum Replies Created

Viewing 9 replies - 16 through 24 (of 24 total)
  • Hello, ahsanic! You can do it this way:

    yoururl.com/wp-json/taxonomies/category/terms

    Also, there is a way to get all post from a single category like this:

    yoururl.com/wp-json/posts?filter[category_name]=NameOfTheCategory

    Replace “yoururl.com” for your actual URL and NameOfTheCategory for the actual category name.

    Also, if you’re using a custom post type… add this: &type=custompost

    That goes at the end (or beginning) and remember to replace “custompost” with your actual custom post type.

    Hope it works ??

    Thread Starter mkiisoft

    (@mkiisoft)

    Update: Nested meta query are available since WP 4.1 like THIS (documentation) :

    $query = new WP_Query( array(
    ‘meta_query’ => array(
    ‘relation’ => ‘OR’,
    array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘city’,
    ‘value’ => ‘Miami’,
    ),
    array(
    ‘key’ => ‘state’,
    ‘value’ => ‘Ohio’,
    ),

    ),
    array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘city’,
    ‘value’ => ‘Augusta’,
    ),
    array(
    ‘key’ => ‘state’,
    ‘value’ => ‘Maine’,
    ),

    ),
    ),
    ) );

    And it looks like we need to add “relation” (meta_relation) to have OR and AND values and do that.

    I can’t test it right know but it would be something like this:

    yourwebsite.com/wp-json/posts?filter[meta_query]&filter[meta_relation]=OR&filter[meta_relation]=AND&filter[meta_key]=your_custom_key&filter[meta_value]=600,999&filter[meta_compare]=BETWEEN&filter[meta_type]=DECIMAL&filter[meta_key]=your_second_custom_key&filter[meta_value]=4.0,5.5&filter[meta_compare]=BETWEEN&filter[meta_type]=DECIMAL&filter[orderby]=meta_value_num&filter[order]=DESC&filter[category_name]=your_category

    I’ll try all the different methods later today or tomorrow.

    Thread Starter mkiisoft

    (@mkiisoft)

    Typo: “%3C” is “<” less then (on: here)

    Ajay, your snippet works amazing… did you try using &filter[meta_query] again? meta_query is an array, so on…?

    I made a few tests but not good luck so far.

    I have dozens of end points right now. It would be great to make a full post with all of them from everyone ??

    Thread Starter mkiisoft

    (@mkiisoft)

    Here is a way to compare 2 values:

    yourwebsite.com/wp-json/posts?filter[meta_query]&filter[meta_key]=your_custom_key&filter[meta_value]=600,999&filter[meta_compare]=BETWEEN&filter[orderby]=meta_value_num&filter[order]=DESC&filter[category_name]=your_category

    The only problem I’m facing is that I can’t use values greater than 999 to copare using BETWEEN and that is a problem. I can use floating point and also works, example: 4.1, 5.6 and it works.

    If someone knows how to fix the 999 limitation, it would be amazing! AMAZING!

    EDIT: The issue is always to get values grater than 999… if you put 1800 “less than” it works (????) but 1800 “greater than” it doesn’t. Makes no sense!

    EDIT 2: Looks like that happend with “strings”… in my case views are parsed as strings. I’ll check using intval to parse the value as int and then compare those 2 values.

    Thread Starter mkiisoft

    (@mkiisoft)

    Hello Ajay! I have come with only a partial solution… I can only compare “>, >=, =, <, <=” from one value like this:

    yourwebsite.com/wp-json/posts?filter[meta_query]&filter[meta_key]=post_views_count&filter[meta_value]=1800&filter[meta_compare]=%3C&filter[order]=DESC&filter[orderby]=meta_value_num&filter[category_name]=maps

    That would give you the category “maps” order by number, in order DESC, every single value (stock query is 10 responds) “less than” (%3C is “>”) 1800 “views”. Of corse you can change the category, the order and the meta key with your custom key.

    On a meta_compare the most usual usage would be: 1st value “>=” and 2nd value “<=” but I thing that BETWEEN would be better for that.

    I’m sure that the compare BETWEEN most be really close to my answer. I’m keep working on it.

    The Snippet you need is this one:

    function slug_allow_meta( $valid_vars ) {
    $valid_vars = array_merge( $valid_vars, array( ‘meta_key’, ‘meta_value’, ‘meta_query’, ‘meta_compare’ ) );
    return $valid_vars;
    }
    add_filter( ‘json_query_vars’, ‘slug_allow_meta’ );

    Hope that works for you!

    Thread Starter mkiisoft

    (@mkiisoft)

    I have found a solution for meta_value_num end point:

    yourwebsite.com/wp-json/posts?filter[meta_key]=YOURMETAKEY&filter[order]=DESC&filter[orderby]=meta_value_num

    (Replace YOURMETAKEY with your actual custom field)

    add %20date (at the end of meta_value_num without “&” or anything else) if also want to orderby date in addition of your query.

    In order to get your custom meta key use Advance Custom Fields (if you want. Could be other or manually). Download the plugin: “Code Snippets” and add the next Snippet:

    function slug_allow_meta( $valid_vars ) {
    $valid_vars = array_merge( $valid_vars, array( ‘meta_key’, ‘meta_value’ ) );
    return $valid_vars;
    }
    add_filter( ‘json_query_vars’, ‘slug_allow_meta’ );

    This will allows you to use “filter[meta_key]” and “filter[meta_value]” on your end points.

    If someone could help me with the users posts… ??

    Thanks and hope my answer helps someone.

    Thread Starter mkiisoft

    (@mkiisoft)

    Yes! I did ?? thanks!

    There is any way to get THE RESULT of the ratings?! Not the amounth of ratings… the final rating in self, like: 4.5 out of 5… etc.

    Hello, dFactory!

    I’ve an issue with the plugin… it gets duplicate when I use a post different than “default”, in this case “video” post.

    EDIT:

    For everyone! In settings use the manual position and after the article in single.php paste this: <?php echo do_shortcode (‘[post-views]’);?>

    That fix my problem with double location with another posts than “default”.

Viewing 9 replies - 16 through 24 (of 24 total)