Using new WP_Query in shortcode in a custom field causes the main post content to not display

You’re using get_posts which returns an array of posts, which you can loop through using foreach, but not the_loop. Try this version of the code: function ia_news_display_test($atts){ // [ia_news cat=”category” num=’numbertodisplay’] extract(shortcode_atts(array( ‘cat’ => ‘any’, ‘num’ => ‘2’, ), $atts)); $dirloop = new WP_Query( array( ‘post_type’ => ‘ia_news’, ‘category_name’ => $cat, ‘posts_per_page’ => $num, ‘orderby’ … Read more

WP Query by Gutenberg block and get its attribute

After hours of googling I came up with following solution. Maybe once will help to someone. 1) query post where is used gutenberg youtube block: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘s’ => ‘core-embed/youtube’, ‘posts_per_page’ => 1 ); $query = new WP_Query($args); 2) extract the URL from youtube block of the post … Read more

Query by 2 values of a repeater ACF field

I know this is an old question, but I thought I’d post the answer in case anybody else is facing the same problem. functions.php: function add_cond_to_where( $where ) { //Replace showings_$ with repeater_slug_$ $where = str_replace(“meta_key = ‘showings_$”, “meta_key LIKE ‘showings_%”, $where); return $where; } add_filter(‘posts_where’, ‘add_cond_to_where’); Query: //Replace showings_$ with repeater_slug_$ //Replace _discounts with … Read more

Single page theme

WordPress queries are indeed represented by WP_Query objects. The snippet example you have is secondary query, as opposed to main query – which is run by WP itself during core load and stored in global $wp_query variable. Typically it is better (for performance and compatibility) to modify main query for set of posts that is … Read more

Select posts with any post_type from database?

By default– that is, unlss told otherwise– WP_Query will search the post post type. You may supply ‘post_type’ => ‘any’ to retrieve all post types, but be aware that things like attachments are post types. For example… $args = array( ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘ignore_sticky_posts’ => true, ‘post_type’ => ‘any’ ); $qry = … Read more

Get only modified posts

You can use the posts_where filter: // Add custom filter add_filter( ‘posts_where’, ‘wpse_modified’ ); // Fetch posts $query = new WP_Query( $lastupdated_args ); where you can define the filter callback as: function wpse_modified( $where ) { global $wpdb; // Run only once: remove_filter( current_filter(), __FUNCTION__ ); // Append custom SQL return $where . ” AND … Read more

meta_query not working properly

Based on the codex, the meta_query parameter contains one or more array with the relation parameter not set if single inner meta_query array. Also remove the page parameter as it serves only for a Static Front Page. Your args array should look like that: $archive_args = array( ‘post_type’ => ‘speight_home_plans’, ‘orderby’=> ‘title’, ‘order’ => ‘ASC’, … Read more