WP API to fetch all the media/posts records if count is more than 100

Add a page number query to your request URL, and continue querying next page numbers until you get an empty result: <your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=100&page=2 Mark’s suggestion to consider requesting less than 100 per page may be a good one. So for example you may want to do your query this way: <your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=25&page=3 Note also that (for me … Read more

WP_Query on different site in a multisite setup

Alternative option could be using the Rest API: Example (post): Search for Jane Doe in posts: https://example.com/staffsite/wp-json/wp/v2/posts/?search=jane+doe Example (custom post types): If the public and searchable custom post type (e.g. staff) has show_in_rest set to true then we can search for Jane Doe in staff posts: https://example.com/staffsite/wp-json/wp/v2/staff/?search=jane+doe ps: Somewhat related, if you want to create … Read more

Using Cookie Data For WP_Query Loop

You need to explode the comma separated string to get the array of IDs. Follow the below code. $cookie_array = $_COOKIE[“your-results”]; // Test output echo $cookie_array; $cookie_array = array_map( ‘absint’, (array) explode(‘,’, $cookie_array) ); $sug_args = array( ‘post_type’ => ‘product’, ‘post__in’ => $cookie_array, ); $sug_query = new WP_query ($sug_args); if( $sug_query->have_posts() ) : while( $sug_query->have_posts() … Read more

Order posts by date and then by custom field

add_filter(‘posts_orderby’, ‘posts_orderby’); function posts_orderby($orderby_for_query) { global $wpdb; $prefix = $wpdb->prefix; $orderby_for_query = “LEFT(” . $prefix . “posts.post_date, 10) DESC, ” . $orderby_for_query; return $orderby_for_query; } This produces this query: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish”) AND (wp_postmeta.meta_key = ‘my_post_rating’ ) GROUP BY wp_posts.ID ORDER … Read more

On Taxonomy Template page, want to add Post_Type

You can use pre_get_posts filter hook to check if you are on the taxonomy page and if so just add your custom post type to the query something like this: function add_my_type( $query ) { if ( $query->is_tax(‘YOUR_TAXONOMY’) ) { $query->set( ‘post_type’, array(‘post’,’YOUR_CUSTOM_POST’) ); } } add_filter( ‘pre_get_posts’, ‘add_my_type’ );

Use post__in and post__not_in together?

post__in and post__not_in are mutually exclusive. Note: you cannot combine post__in and post__not_in in the same query. http://codex.wordpress.org/Class_Reference/WP_Query As your question is written, the solution you reject– that of using array_diff— is the obvious answer. If it is true that that solution won’t work you will need a filter on posts_where (probably) that will provide … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)