Support

Account

Home Forums General Issues Querying custom field value?

Unread

Querying custom field value?

  • Hi

    I have been trying to find a way of querying $monthly_revenue post type to retrieve the total_revenue of that months value.

    Currently, I have been working with using post ID, but because they are not in sequence I can’t do it.

    I have added a new custom field called (month_year), the format in this is May 2018.

    My thinking is that I use $jan_rev = get_field(‘total_revenue’, Jan 2018); to get the value, but not sure if that would work?

    Any help would be great!

    <?php
    	$args = array(
    		'post_type' => 'monthly_revenue',
    		
    		'post_status' => 'publish',
    		
    	
    		
    	);
    	$monthly_revenue = new WP_Query( $args ); ?>
    
    	<?php if ( $monthly_revenue->have_posts() ) :
    		while ( $monthly_revenue->have_posts() ) : $monthly_revenue->the_post();
    
    			
    			$jan_rev = get_field('total_revenue', 87);
    			$feb_rev = get_field('total_revenue', 103);
    			$mar_rev = get_field('total_revenue', 106);
    			$apr_rev = get_field('total_revenue', 87);
    			$may_rev = get_field('total_revenue', 87);
    			$jun_rev = get_field('total_revenue', 87);
    			$jul_rev = get_field('total_revenue', 87);
    			$aug_rev = get_field('total_revenue', 87);
    			$sep_rev = get_field('total_revenue', 87);
    			$oct_rev = get_field('total_revenue', 87);
    			$nov_rev = get_field('total_revenue', 87);
    			$dec_rev = get_field('total_revenue', 87);
    			
    			?>
    
    	<?php endwhile;?>
    
    			<?php wp_reset_postdata();?>
    		
    		<?php endif; ?>
    
    
Viewing 1 post (of 1 total)

The topic ‘Querying custom field value?’ is closed to new replies.