Rewrite and custom post type: order by custom field not working

If your post type slug is placement, and you set has_archive to true, then the archive WordPress generates is at /placement/. Set has_archive to placements instead and let WordPress add the rewrite rules (which will also handle pagination properly). Then, to order by your meta key, add a function hooked to pre_get_posts, check if the … Read more

Reorder displayed posts with JQuery (title A-Z / last posted)

With WordPress you can utilise a function called wp_localize_script() which allows you to pass in a script, and a variable you would like that script to have access too. Perhaps by assigning the new query to a variable, and then accessing it within jQuery would help you solve your problem. The example provided by WordPress … Read more

Order By table field comment_status in WordPress > 4.0

Here’s a way to add an extra Comment Status field to the posts list table: add_filter(‘manage_post_posts_columns’, function ( $columns ) { $_columns = []; foreach( (array) $columns as $key => $label ) { $_columns[$key] = $label; if( ‘title’ === $key ) $_columns[‘wpse_comment_status’] = esc_html__( ‘Comment Status’, ‘mydomain’ ); } return $_columns; } ); add_action( ‘manage_post_posts_custom_column’, … Read more

SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)

Solved. After the edit it was easy. It is allowed to use type => ‘decimal(x,x)’ in meta_query. Maximum precision is decimal(65,30). https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html array(6) { [“orderby”]=> array(2) { [“uss_product_price”]=> string(4) “DESC” [“title”]=> string(3) “ASC” } [“meta_query”]=> array(3) { [“relation”]=> string(3) “AND” [“sortprimary_clause”]=> array(3) { [“key”]=> string(17) “price” [“compare”]=> string(6) “EXISTS” [“type”]=> string(13) “decimal(30,5)” } [0]=> array(4) … Read more

get_query_var returns wrong default value

The default value of get_query_var( $var, $default ) is only returned if the query variable $var isn’t available in the global $wp_query object. The order query variable actually falls back to the DESC value here: if ( ! isset( $q[‘order’] ) ) { $q[‘order’] = $rand ? ” : ‘DESC’; } … within WP_Query::get_posts(), so … Read more

WP_Query ordered by meta_value_num doesn’t fetch posts without this meta field

The reason you’re only getting those users that have that meta_key is because you’re include ‘meta_key’ => ‘…’ in $args. That limits results to those that have that key, regardless of any clauses you may have in a meta_query. This applies to WP_Query, WP_User_Query and WP_Comment_Query. Starting in WP 4.2, you can “name” the clauses … Read more

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