Sorting: custom query with orderby meta_value_num THEN by title

This is very crude but should sort your posts by year (meta_value) and then by title. It does depend on how the query is setup so it will only work with the query below or with similar ones. function alter_order_wpse_103181($order,$qry) { remove_filter(‘posts_orderby’,’alter_order’,1,2); $order = explode(‘,’,$order); $order = implode( ‘ ASC,’,$order); return $order; } add_filter(‘posts_orderby’,’alter_order_wpse_103181′,1,2); $q … Read more

How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?

I had a similar issue but couldn’t solved with the snippets on this thread. I had to order a query by: all ‘featured’ posts first (is_it_a_featured_etf) and by a numeric field (etf_aum) in DESC order after the featured ones. My solution: ‘meta_query’ => [ ‘relation’ => ‘OR’, ‘etf_aum’ => array( ‘key’ => ‘etf_aum’, ‘type’ => … Read more

get_queried_object() returns null on post date archive

so my question is, is this intended functionality (e.g. are you not supposed to use get_queried_object() on those pages), a technical limitation (is there not a meaningful object to return on those pages), or simply an implementation oversight? get_queried_object() is to get the term, author, single post, single custom post type, or page object being … Read more

Set Alias for meta_query arguments in get_posts()

Have a look at the meta_query_find_compatible_table_alias filter defined in wp-includes/class-wp-meta-query.php. This filter’s documentation: /** * Filters the table alias identified as compatible with the current clause. * * @since 4.1.0 * * @param string|bool $alias Table alias, or false if none was found. * @param array $clause First-order query clause. * @param array $parent_query Parent … Read more

What is “main query”? [duplicate]

Your filter has a bug in it, namely when you call is_main_query, you’re not checking if the passed query is the main query, your checking if the currently active query is the main query, which will always be true. So instead try this: add_action( ‘pre_get_posts’, ‘some_name’); function some_name($query) { if ($query->is_front_page() && $query->is_main_query()) { $query->set( … Read more

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