Custom Post type sort order not working in the admin area

The ‘title’ and ‘date’ columns are WordPress default tables (even for CPTs) so they should be automatically sortable, unless those columns have been replaced. For custom columns there is a hook for registering a column as ‘sortable’: https://developer.wordpress.org/reference/hooks/manage_this-screen-id_sortable_columns/ //Filter is ‘manage_edit-{custom post type}_sortable_columns //or more generally ‘manage_{screen id}_sortable_columns add_filter( ‘manage_edit-cpt_sortable_columns’, ‘wpse221267_cpt_sortable_columns’ ); function wpse221267_cpt_sortable_columns( $columns … Read more

Identifying the priority of style.css so I can make a small CSS file load last

When you properly enqueue a file, an instance of the wp_styles (more on this) class is created. The priority of actions is ignored. So it doesn’t matter if you write anything like add_action (‘wp_enqueue_scripts’,’function_adding_main_style’,10); add_action (‘wp_enqueue_scripts’,’function_adding_small_style’,11); The reason is exactly the existence of the dependency system. WP first collects all enqueued style files and then … Read more

WP REST API: Order posts by meta value (acf)?

I’m guessing you haven’t exposed meta_key and meta_value to the REST API with the rest_query_vars filter, so this should do it: function my_add_meta_vars ($current_vars) { $current_vars = array_merge ($current_vars, array (‘meta_key’, ‘meta_value’)); return $current_vars; } add_filter (‘rest_query_vars’, ‘my_add_meta_vars’); Then you can refer to meta_key and meta_value in your query. Be aware that this obviously exposes … Read more

Ensuring a plugin is loaded/run last?

You’ll want to hook into “the_content” filter at a very high priority. Example: function my_alter_the_content( $content ) { if ( in_array( get_post_type(), array( ‘post’, ‘page’ ) ) ) { // Do stuff here for posts and pages } return $content; } add_action( ‘the_content’, ‘my_alter_the_content’, PHP_INT_MAX ); Using the PHP_INT_MAX constant for the hook priority you … Read more

Order Posts by Taxonomy and Meta Value

In your code, there is if ( isset( $wp_query->query[‘orderby’] ) && $taxonomy == $wp_query->query[‘orderby’] that make your code not work with multiple order fields, because if you set ‘orderby’ => ‘taxonomy_cat meta_value’ then $taxonomy == $wp_query->query[‘orderby’] is never true. In addition, I find that looping all taxonomy only with the aim to find the taxonomy … Read more

Query by one meta_key and sort by another (possibly NULL value)

I don’t think there’s a way to do it without using filters. Using posts_clauses you could do: function wpse163696_posts_clauses( $pieces, $query ) { if ( $query->get( ‘orderby’ ) != ‘dealer_date’ ) { return $pieces; } global $wpdb; $order = $query->get( ‘order’ ); $pieces[ ‘join’ ] .= $wpdb->prepare( ‘ LEFT JOIN ‘ . $wpdb->postmeta . ‘ … Read more

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