How to `’orderby’ => ‘meta_value_num’` in a series of orderby parameters

The documentation for WP_Query indicates that ordering by meta value is limited to one meta key and requires the meta_key parameter (untested): $results = new WP_Query( array( ‘meta_key’ => ‘wpcf_catalogue_number’, ‘orderby’ => array( ‘meta_value_num’ => ‘ASC’, ), ) ); If you want additional sorting, you’ll need to sort the result ($results->posts) using PHP (untested): $sort__formats … Read more

Best Practice for storing aggregate data by date or other criteria?

I settled on using wp_cache_set and wp_cache_get which seems to do well. I create a key based on the class, function, and parameters: $cacheKey = self::createCacheKey( __CLASS__, __FUNCTION__, $referenceYear, $referenceMonth ); createCacheKey() looks like: protected static function createCacheKey( …$args ): string { return implode(‘-‘, $args); } And I’m sure to use an appropriate expiration. For … Read more

copy the Value from one Meta to another Meta

If you just need get_post_meta( $post_id, ‘ywbc_barcode_display_value_custom_field’, $single ); to return the value that’s stored in ean, you can filter the get_post_meta() call to return that value: add_filter( ‘get_post_metadata’, ‘wpse424858_filter_meta_value’, 10, 4 ); /** * Filters the barcode display meta value. * * @param mixed $value The existing meta value. * @param int $id The … Read more

Can I count every article following extracted meta value?

Use array_count_values() (untested): <?php $posts = get_posts( array( ‘numberposts’ => -1, ‘category_name’ => ‘bird’, ‘order’ => ‘ASC’, ) ); if ( $posts ) { foreach( $posts as $post ) { $species[] = get_post_meta( $post->ID, ‘species1’, true ); $species[] = get_post_meta( $post->ID, ‘species2’, true ); } } $species = array_filter( $species ); $counts = array_count_values( $species … Read more

Get meta value based on user id

get_users is for retrieving users, not meta. To get the user meta of a user where $user_id is that users ID, you can use get_user_meta and it should work the same as the other meta functions: $meta_value = get_user_meta( $user_id, ‘the meta key’, true ); You can use $user_id = get_current_user_id(); to retrieve the ID … Read more

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