Best Practice For Querying Grandchildren?

You’re on the right track. You can do this with just one MySQL query instead of two by joining on the post_parent. Drop this function into your functions.php file, then in your template you can replace your WP_Query call with $results = wpse_84810_get_grandchildren();, change your if clause to be if( $results && $results->have_posts() ), then … Read more

How do I search WordPress by different fields without a plugin?

I found a solution that allows me to search posts by tags and categories while still searching title and content. This does exactly what I was looking for. Credit: https://rfmeier.net/include-category-and-post-tag-names-in-the-wordpress-search/ add_filter( ‘posts_join’, ‘search_join’, 10, 2 ); /** * Joins the terms, term_relationship, and term_taxonomy tables. * * @global $wpdb * * @param string $join The … Read more

Search Custom Post with meta_value NULL

I depends if you’re looking for an empty value: $args = array( ‘post_type’ => LANDING__CUSTOM_POST, ‘meta_query’ => array( array( ‘key’ => ‘landing_exported’, ‘value’ => ”, ‘compare’ => ‘=’ ) ) ); // query $the_query = new WP_Query( $args ); which searches for value like: meta_value=”” or if you are looking for actually a NULL value … 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

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

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