Home Forums General Issues Querying a Post Object relation field inside a repeater Reply To: Querying a Post Object relation field inside a repeater

  • Thanks, James. That helped get me on my way. What threw me off were the percentage marks and incorrectly assuming that the related code only applied to dates, or was something I couldn’t modify to my purpose, to my particular variables.

    I also was wrong in how I told the query to pull up posts matching a value on a checkbox. Anyway, for the interests, here’s what I ended up using. This query looks for posts of another content type that 1) are linked through post object to the current page’s content type, and 2) either are (in this case) or aren’t checked in a checkbox indicating department head status.

    // filter
    function my_posts_where( $where ) {
    	$where = str_replace("meta_key = 'person_department_%", "meta_key LIKE 'person_department_%", $where);
    	return $where;
    add_filter('posts_where', 'my_posts_where');
    	// checks if there's a department head
    	// if so, displays that person
    	// args
    	$args_faculty_head = array(
    		'posts_per_page'	=> -1,
    		'post_type'		=> 'people',
    		'orderby' => 'title',
    		'order' => 'ASC',
    		'meta_query'	=> array(
    			'relation'		=> 'AND',
    				'key'		=> 'person_department_%_person_department_select', // this should be the first sub-field
    				'value' => get_the_ID(),
    				'compare' => '='
    				'key'		=> 'person_department_%_person_department_head', // this should be the second sub-field
    				'value' => '"Yes"',
    				'compare' => 'LIKE'
    	// query
    	$the_query = new WP_Query( $args_faculty_head );
    	<?php if( $the_query->have_posts() ): ?>
    		<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    				<?php the_title(); ?>
    		<?php endwhile; ?>
    	<?php endif; ?>
    	<?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>