Support

Account

Home Forums General Issues Get Field from Custom Post Typ Reply To: Get Field from Custom Post Typ

  • Events is taxonomy 'post_type' => 'events' but when I add

    $term = get_queried_object()->term_id;
    print_r($term);

    to code here inside the while loop nothing is printed. The new query does already load the events custom post type, but now with fields added I want to load them too.

    <?php 
    
    // Variables
    $number_of_events = get_field( 'number_of_events' );
    // print_r($number_of_events);
    $event_categories = get_field('event_categories');
    $event_cat_ids = wp_list_pluck( $event_categories, 'term_id' );
    
    $args = array(
    		'post_type' 		=> 'event',
    		'post_status'		=> 'publish',
    		'posts_per_page'	=> $number_of_events,
    		'order'				=> 'DESC',
    );
    			
    $args['tax_query'] = array(
    	'relation' 		=> 'OR', 
    
    	array(
    		'taxonomy'	=> 'event_category',
    		'field'		=> 'term_id',
    		'terms'		=> $event_cat_ids
    	),			
    		
    );
    
    $query = new WP_Query( $args );
    if( $query->have_posts() ) : ?> 
    	<div class="event-grid">
    		<?php while( $query->have_posts() ): $query->the_post();
    		$term = get_queried_object()->term_id;
    		print_r($term);
    		// $date_and_time = get_field('date_and_time', $term);
    		// print_r($date_and_time);
    		// $date_number = get_field('date_number');
    		// $date_number = get_field('date_and_time');
    		// $event_title = get_field('event_title');
    		// $event_location = get_field('event_location');
    		// $event_description = get_field('event_description'); 
    		?>
    			<div class="block-box event-box">
    				<div class="event-number-container">
    					<p class="event-number">date<?php //echo $date_number; ?>
    
    				</div>
    				<div class="event-details">
    					<p class="event-date-time"><?php // echo $date_and_time; ?>
    
    					<h4 class="event-title"><?php the_title(); ?></h4>
    					<p class="event-location">event location<?php // echo $event_location; ?>
    
    				</div>
    			</div>
    		<?php endwhile;  wp_reset_postdata();
    endif;
    ?>

    So I used $term = $query->get_queried_object()->term_id; and did get id 146. so making progress here.

    Getting the date_and_time field for posts queried do not load yet though.. we also use more categories for the events cpt of course..

    $term = $query->get_queried_object()->term_id;
    // print_r($term);
    $date_and_time = get_field('date_and_time', $term);
    print_r($date_and_time);

    I guess I may need to focus on the custom post type and not the term here?