Sort by presence of thumbnail

Easy peasy! $args_for_query1 = [ ‘post_type’ => ‘custom_project’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘_thumbnail_id’ ) ) ]; $args_for_query2 = [ ‘post_type’ => ‘custom_project’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘_thumbnail_id’, ‘meta_compare’ => ‘NOT EXISTS’, ]; $query1 = new WP_Query($args_for_query1); $query2 = new WP_Query($args_for_query2); $wp_query = new WP_Query(); $wp_query->posts = array_merge( $query1->posts, $query2->posts … Read more

Differentiate Nested WP_Query from Parent

You could check if the current post ID is the same as the ‘queried object’ ID, which is whichever post the current URL represents, and is separate from the current post within the loop. If both those IDs are the same then you can assume that the current content being filtered is for the content … Read more

Continue or break the while loop

‘break’ is the right keyword… code structure below, no custom query needed if used in a standard template. <?php $posts_per_first_section = 6; //how many posts you want to show in the first section// if ( have_posts() ) : ?> <!– opening html for first loop –> <?php /* Start the Loop */ while ( have_posts() … Read more

How to load a script code only in posts?

In the active theme, functions.php file or in your plugin, function load_scripts() { if ( is_singular( ‘post’ ) ) { // Load the Javascript wp_enqueue_script( string $handle, string $src=””, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false ); } } add_action( ‘wp_enqueue_scripts’, ‘load_scripts’ );

Is it possible (and how to) query single Gutenberg blocks?

My own answer is: somewhat yes, but not so easily. We can use 2 functions: https://developer.wordpress.org/reference/functions/parse_blocks/ https://developer.wordpress.org/reference/functions/render_block/ Not very well documented yet. But you can pass raw content to parse_blocks to have them back in array form. The thing is that they don’t have some sort of ID. So this approach is not always usefult, … Read more