Passing additional variables to a query

If you’re running a custom query like $blog_query, add them right in. If you are wanting to change the main query, use the pre_get_posts action to alter the function. add_action( ‘pre_get_posts’, ‘alter_blog_order’ ); function alter_blog_order( $query ) { if( $query->is_main_query() and $query->is_post_type_archive( ‘post’ ) ) { $query->set( array( ‘orderby’ => ‘post-title’, ‘order’ => ‘ASC’ ) … Read more

Getting grandchildren of a post with a specified custom taxonomy?

I was able to achieve this by, funnily enough, using with get_pages() and WP_Query(). I wanted a reusable function that would return a WP_Query array that I could loop through, so I came up with this: function returnChildGeographies($geoID, $geoType, $grandChildren = false) { $args = array( ‘post_type’ => ‘geographies’, ‘posts_per_page’ => -1, ‘orderby’ => ‘post_title’, … Read more

Fallback if statement based on the number filtered from it

Got some help from a friend and figured out that I needed to move the post_meta stuff into the query with meta_query then just set a fallback from there. <?php $current_date = date(‘Ymd’); $page_object = get_queried_object(); $page_id = get_queried_object_id(); // Match the string “123” to the database value a:1:{i:0;s:3:”123″;} (serialized array) for ACF $page_id = … Read more

Getting Year & Date inside wpdb [duplicate]

You mention the Codex page for WP_Query but you are not using WP_Query. You are using wpdb. WP_Query is a very complicated class for querying the WordPress tables for post (CPT) data. wpdb is a lightweight wrapper around PHP SQL functions. With WP_Query you can pass arguments like monthnum because the WP_Query class converts the … Read more

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