Are there sub-systems in WordPress that would employ data structures beyond CPT that a `get_posts` won’t be able to catch?

Actually if you look closely to the codex, you can see that setting ‘post_type’ argument to any will by default leave out some post types from the query: https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters ‘any’ – retrieves any type except revisions and types with ‘exclude_from_search’ set to true. So you can actually register a post type and make it non-public, … Read more

`get_posts()` ignore my custom post

If we do not specify post types, WordPress searches only ‘posts’ $actus_new = get_posts( array( ‘post_type’ => array( ‘cantine’, ‘post’ ), ‘post__in’ => $ids, ‘posts_per_page’ => 5, ) );

var_dump and print_r cause white screen

Actually, memory was exhausted. Someone has copy-pasted an actual 2MB base64-encoded image into the post content, var_dump was trying to output it. Had to delete the image via PHPMyAdmin, because the WP editor won’t open. Once it had been deleted, the problem was gone.

If clauses in get_posts query

only retrieve posts with that meta key: $rand_posts = get_posts(array( ‘numberposts’ => 4, ‘orderby’ => ‘rand’, ‘post_type’ => ‘ansatte’, ‘order’ => ‘ASC’, ‘meta_key’ => ’employee_pic’, )); or maybe use WP 3.1’s meta_query: $rand_posts = get_posts(array( ‘numberposts’ => 4, ‘orderby’ => ‘rand’, ‘post_type’ => ‘ansatte’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ’employee_pic’, ‘value’ … Read more

making random query button using $_GET

You cannot use the direct class methods have_posts() or the_post() unless you’re working with the main query. In order to modify the main query you must use query_posts. If you want to create a new query object you need to call those methods from the new query object as Rarst showed in his example. So … Read more

Secondary Query Is Breaking Main Query

you don’t need to call wp_reset_postdata() for get_posts() because it does not actually modify global variable $wp_query. $posts though is a global variable used by WordPress. Change that to a new name and what you have should work. $args = array( ‘post_type’ => ‘quote’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’ ); $quote_posts = get_posts( $args … Read more

Filter the content from a post globally immediately after is fetched from the database

Inside get_posts() method of the WP_Query class (line 3769), you will find out this filter: $this->posts = apply_filters_ref_array( ‘the_posts’, array( $this->posts, &$this ) ); It’s the very first hook you can use to modify queried posts on both back-end and front-end. $this->posts is an array of queried posts so it’s easy to modify the content … Read more