WP API JOIN clause method POST filter posts relative to a JSON sent

  • Unknown's avatar

    I’m using WP API. Initially I used the method GET and in the callback function a query to WPDB (with JOIN clause – postmeta & users tables) The postmeta table has several columns (meta_key, meta_value, type…) Now I registered a rest route with method POST. I want to get communication between an external application and wordPress (the application send a JSON (linked to postmetas values; ex: {‘type’:[‘value’]}) to WP and get back a response. I only want to get back in a JSON the posts corresponding to the external app request. How can I do that?

    Thanks

    <?php
        add_action("rest_api_init", function() {
            register_rest_route('posts/', 'filters', array(
                'methods' => 'POST',
                'callback' => 'getPostsFiltered',
            ));
        });
    
        function getPostsFiltered($data) {
            global $wpdb;
            $query = "SELECT ... LEFT JOIN..ON"
            $list = $wpdb->get_results($query);
            return $list;
        }
  • Unknown's avatar

    Hi there, it would appear like you are self-hosted and not hosted here at WordPress.com.

    If that is true, then i would suggest posting in the WordPress.org support forums at https://wordpress.org/support/

    If you are talking about a site hosted here, can we have a link to that site?

  • The topic ‘WP API JOIN clause method POST filter posts relative to a JSON sent’ is closed to new replies.