List most recent image uploads, but only for specific custom post type

Did you try adding a filter to get_posts. This isn’t tested, just a thought after a bit of searching : function my_filter( $query ) { if( is_home() ) //Example, if u want to display recent images on home { $query->set( ‘post_type’, array( ‘attachment’, ‘my_cpt’ ) ); } } add_filter( ‘pre_get_posts’, ‘my_filter’ ); EDIT : After … Read more

Get Recent Posts by Date in Multisite

Since wordpress multisite uses different tables for all blogs, it is very inefficient to get all recent articles of all blogs (content aggregation) on display time since you have to query all blogs, sort the articles by date and display the ammount you need. Plugins like WordPress Post Indexer (https://premium.wpmudev.org/project/post-indexer) additional write all posts into … Read more

Is the first item returned by get_posts() always the latest post?

Yes and Maybe Yes: According to https://developer.wordpress.org/reference/functions/get_posts/ the default is ordered by date in a descending order. Maybe: But plugins may change the query through ie hook(s) pre_get_posts. https://developer.wordpress.org/reference/hooks/pre_get_posts/ https://developer.wordpress.org/reference/classes/featured_content/pre_get_posts/

get_posts with meta_compare=’LIKE’ not working

meta_compare Possible values are ‘!=’, ‘>’, ‘>=’, ‘<‘, or ‘<=’. Default value is ‘=’ if you want to use LIKE you need to create a meta_query eg: $tolettpe = “Sale”;//default if($_REQUEST[‘tolettype’]) $tolettpe = $_REQUEST[‘tolettype’]; else if($_REQUEST[‘srch_type’]) $tolettpe = $_REQUEST[‘srch_type’]; $args = array( ‘numberposts’ => $latestcount, ‘category’ => $catidstr, ‘meta_query’ => array( array( ‘key’ => ‘property_type’, … Read more

How to get current post ID in quick edit callback

You can get the ID per JavaScript from the quick edit screen’s parent tr: that has an attribute id=”edit-418″, where 418 is the post ID. So extract this number, get the post data per AJAX, and insert the values you need. Not elegant. Read wp-admin/js/inline-edit-post.js to see how the core does it.

Delete all posts from WordPress except latest X posts

The offset parameter is ignored with posts_per_page set to -1 in WP_Query. If you look at the source code in the WP_Query class, posts_per_page=-1 sets nopaging to true. if ( !isset($q[‘nopaging’]) ) { if ( $q[‘posts_per_page’] == -1 ) { $q[‘nopaging’] = true; } else { $q[‘nopaging’] = false; } } This in turn will … Read more