1

I try to use wordpress configured as multisite. The /posts url return posts fine except one site.

From one site (site_id:2) where posts is actually exists the /posts api endpoint returns an empty array.

Another endpoints like /media and /comments returns json with data which refers to some posts by id. But endponts like /posts/{id} where id is actually posts returns error json with error:

{"code":"rest_post_invalid_id","message":"Invalid post ID.","data":{"status":404}}

When I call get_current_site() at the place where above error is fired it return same data for all the sites (for all urls which is associated to each site), however for (site_id: 1 or 3) as mentioned above list of posts generated by rest api is not empty, problem only with /posts for site id:2.

What are possible to check?

Is any palce in wp where I can intercept all sql queries?

2 Answers 2

0

You can intercept WordPress SQL queries using the following:

<?php echo $GLOBALS['wp_query']->request; ?>

Another example is

$customPosts = new WP_Query($yourArgs);
echo "Last SQL-Query: {$customPosts->request}";

Another method would be to utilize this functions.php file code at the link below.

Best Collection of Code for your functions.php file

Sign up to request clarification or add additional context in comments.

1 Comment

I do not found any hook to intercept queries. (First of your line is actually empty and secod seems does not intercepts the posts queries). I dump or just return query directly from wordpress get_posts function.
0

I dump or just return query directly from wordpress get_posts function. And the query appears actually worked and return the post by id.

But after returning the post from get_posts the function get_post of WP_REST_Posts_Controller class check that its field post_type is equal post_type of returned post. And if it is not equal it fires a mentioned in question error.

The error does not actually describe a problem. Actually the post type is not equal to post type of controller.

Actually post type of posts was not a post but page.

So need to switch to use rest endpoint from /posts to /pages.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.