Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nkudev

    (@nkudev)

    I found a solution for my Problem. What i did is quite simple. I just setted up a new Query Params.

    if (!function_exists('post_meta_rest_api_request')) :
        function post_meta_rest_api_request($argu, $request)
        {
    
            $argu += array(
                'meta_key' => $request['meta_key'],
                'meta_value' => $request['meta_value'],
                'meta_query' => $request['meta_query'] == 1 ? array(
                array(
                    "key" => "key1",
                    "value" => "value1"
                ),
                array(
                    "key" => "key2",
                    "value" => "value2"
                )
            ) : $request['meta_query']
            );
    
            return $argu;
        }
        add_filter('rest_custom_query', 'post_meta_rest_api_request', 99, 2);
    endif;

    So if you now make an API call like: wordpress/wp-json/wp/v2/customType?meta_query=1
    the API Request will take in your custom Query Params. Otherwise it will just take in the normal Meta Query Request.
    For references look here: WordPress Rest-API Requests

    • This reply was modified 6 years, 1 month ago by nkudev.
    Thread Starter nkudev

    (@nkudev)

    So i got this for enableling a Meta request per API.

    if (!function_exists('post_meta_rest_api_request')) :
        function post_meta_rest_api_request($argu, $request)
        {
    
            $argu += array(
                'meta_key' => $request['meta_key'],
                'meta_value' => $request['meta_value'],
                'meta_query' => $request['meta_query'],
            );
    
            return $argu;
        }
        add_filter('rest_custom_query', 'post_meta_rest_api_request', 99, 2);
    endif;

    How am i gonna do a meta_query over the API. Could you give any example ?

    Thread Starter nkudev

    (@nkudev)

    I got an custom Enpoint wich is looking like this: “wordpress/wp-json/wp/v2/newtype”. It’s not the default route for Posts. I’m trying to get Posts by multiple meta_keys and meta_values. What i already can do is to get a Post by One meta_key and meta_value but not multiple. How can i do it that it takes multiple Meta Data in the request.

    Or how can i get all Posts with their Meta Data of a custom type Post. I alreay tried doing it with “new WP_Query”. This is working im getting my Posts but without any Meta Data. How can i get the Posts with their Meta Data ?

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