Get all of a user’s posts (custom post type) then get cumulative value of a specific meta_key value from those posts

add_shortcode( ‘show_total_listing_price’, ‘show_total_listing_price’ ); function show_total_listing_price ( $atts ) { global $post; $args = array( ‘author’ => get_current_user_id(), ‘post_type’ => ‘POST_TYPE_GOES_HERE’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ); $query = new WP_Query( $args ); $total = 0; if( $query->have_posts() ){ while( $query->have_posts() ){ $query->the_post(); $price = get_post_meta( $post->ID, ‘PLACE_META_KEY_HERE’, true ); $total += $price; } … Read more

register_rest_field update_callback don’t work for $_FILES

I found a solution but i’m sure there is a better way. I add an action on rest_insert_<post_type> hook add_action( ‘rest_insert_project’, ‘prefix_update_files_field’, 10 , 3 ); function prefix_update_files_field($post, $request, $true){ global $wp_rest_additional_fields; $my_post_type=”project”; $additional_fields = $wp_rest_additional_fields[$my_post_type]; foreach ( $additional_fields as $field_name => $field_options ) { if ( ! $field_options[‘update_callback’] ) { continue; } // Don’t … Read more

Create and Update 2 CPT sequentially

I’ve found a solution, which I’m not liking much, but it works Essentially what I do is create two hooks to save_post (in this case this is the action that launches this script) with different priorities for example 10 and 20 In the priority 10 I put the wp_insert_post And in the priority 20 I … Read more