How to make OR condition in WP_Query

WP_Query does not handle this sort of query: use two instances of WP_Query, and then combine the results. Untested code: $posts = new WP_Query( array( ‘post_type’ => ‘post’, ) ); $post_ids = array_column( $posts->posts, ‘ID’ ); $author = new WP_Query( array( ‘post_type’ => ‘any’, ‘author’ => 123, ‘post__not_in’ => $post_ids, // prevent duplicates ) ); … Read more

new WP_Query with order args – no more distinction between categories

On the template driving your archive page, you can use the query_posts() function to adjust the main query (WordPress’ default main query, not your custom one). query_posts( array( ‘orderby’ => ‘modified’, ‘order’ => ‘ASC’, ) ); Using the pre_get_posts action is the better method, though slightly more complex (untested, would go in theme’s functions.php or … Read more

Accessing Correct Database to Create REST API Endpoint

You can access another database using the wpdb class and its associated methods. You will need to instantiate a new connection to the other database using the appropriate credentials. Here is the basic code to set up the new connection and query the database: $mydb = new wpdb(‘username’,’password’,’database’,’localhost’); $rows = $mydb->get_results(“<your SQL query here>”); Replace … Read more