SQL query based on two different custom field values
SQL query based on two different custom field values
SQL query based on two different custom field values
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
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
You could for example save an error flag to a transient in save_post, if a required field is empty, and the display the admin notice based on the transient. This concept is demonstrated in in this old answer. Another option is to add a simple script to the editing view which would alert the user … Read more
I think you’re close. In my code I’ve assumed that the desired customer_email meta looks like this: array( 0 => ‘[email protected]’, 1 => ‘[email protected]’, 2 => ‘[email protected]’, ); What you need to do is add the new email address to the array of existing email addresses, then save the updated array back to the meta … Read more
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_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
printing taxonomy and meta fields values
You can set the keys of the array to be user-friendly, but more appropriate would be to define the options array in a function, and then use that function in both the backend and frontend (untested): Array function product_condition_array() { return array( ‘new’ => __( ‘New’, ‘woocommerce’ ), ‘like_new’ => __( ‘New other (see description) … Read more
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