Using Orderby and meta_value to order natural/alphanumerical

The orderby argument is limited by what is possible in MySQL, and it’s not good at natural alphanumeric sorting like you describe. Possible options include: Rewriting the values with leading zeros, e.g. “CA05” Creating a separate “Sort Order” column that just stores an integer, and ordering by that. Separating the letters and numbers into two … Read more

WordPress meta query with meta serialized data array value

Probably should have waited a bit but after posting the question I found a solution based on my points above and repeated here: https://codex.wordpress.org/Class_Reference/WP_Meta_Query https://generatewp.com/filtering-data-with-wp_meta_query/ My Solution: $metaSearchSubQuery = [ ‘relation’ => ‘OR’ ]; foreach($eventTypeId as $id) { $metaSearchSubQuery[] = [ ‘key’ => ‘EventId’, ‘value’ => serialize($id), ‘compare’ => ‘like’ ]; } $metaSearchQuery[] = $metaSearchSubQuery;

how to SELECT meta values that are not null?

I founded myself my searching: $sql = $wpdb->prepare( ” SELECT meta_value FROM {$wpdb->prefix}commentmeta INNER JOIN {$wpdb->prefix}comments ON {$wpdb->prefix}commentmeta.comment_id = {$wpdb->prefix}comments.comment_ID WHERE comment_post_ID = %d AND meta_key = ‘rating’ AND meta_value IS NOT NULL AND meta_value <> ” “, get_the_ID() ); $results = $wpdb->get_results( $sql );

Prepare WPDB with meta key and meta value

If you run this query manually, you should get a response like (1054, “Unknown column ‘wp_postmeta.meta_key’ in ‘where clause’”) Long story short, wp_postmeta.meta_key is not a valid column of wp_posts. You need to JOIN the postmeta table to be able to use its columns. (There are many resources out there that explain JOIN, one would … Read more

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