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

Search custom post type posts only by meta fields?

This might work, not tested though. First add this to join the postmeta table: add_filter( ‘posts_join’, ‘search_filters_join’, 501, 2 ); function search_filters_join( $join, $query ) { global $wpdb; if ( empty( $query->query_vars[ ‘post_type’ ] ) || $query->query_vars[ ‘post_type’ ] !== ‘product’ ) { return $join; // skip processing } if ( ($this->is_ajax_search() || $this->is_search_page()) && … Read more