Support

Account

Forum Replies Created

  • Not able to check now, but I’m pretty sure I tried that solution. The issue is that code, with using the % sign as a variable, checks for that role in ANY department, not the specific one in question.

    But I’ll confirm in a little bit and submit a ticket if I need to. Thanks!

  • To further clarify, this is how it should be on the single Department page…

    Department Head(s)
    [listing of name(s) of department heads for only this particular department]

    Supporting Faculty
    [listing of names of supporting faculty for only this particular department]

    In the above Glass Casting department page, Jeremy should ONLY appear as the department head, not as a supporting faculty member as well.

  • Sure, let me try to illustrate this.

    Here are the subfields for the person_department in the the People custom post type.

    Here’s Jeremy’s information in this repeater. He’s the head of the Glass Casting department, but only a “supporting” member in other departments.

    Then, here’s the Glass Casting department “post” in the Department custom post type. It uses single-department.php.

    Jeremy appears as the Head of the Glass Casting department. But he also appears in Supporting faculty. And it seems because the code recognizes that yes he IS a supporting member of *a* department. But I want the query to only search for head or supporting members of this particular department. That way, only the applicable people will appear in each faculty section, un like whats’s showing now.

  • 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.

    
    <?php
    
    // 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',
    			array(
    				'key'		=> 'person_department_%_person_department_select', // this should be the first sub-field
    				'value' => get_the_ID(),
    				'compare' => '='
    			),
    			array(
    				'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() ): ?>
    
    		<ul>
    		<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			<li>
    				<?php the_title(); ?>
    			</li>
    		<?php endwhile; ?>
    		</ul>
    	<?php endif; ?>
    	<?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>
    
    
  • Thanks for pointing me in the right direction. I tried taking that and modifying it for my needs, but I’ve made it so incredibly wrong.

    One issue, I think, so that I’m not properly telling it to “go to People custom post type, look for the person_department repeater field, and then give me the value for person_departmetn_select subfield -if- person_department_head field checkbox subfield is checked.”

    Here’s what I have so far…

    
    
    						<?php
    
    						// args
    						$args = array(
    							'numberposts'	=> -1,
    							'post_type'		=> 'people',
    							'meta_query'	=> array(
    								'relation'		=> 'AND',
    								array(
    									'key'		=> 'person_department_select', // this should be the first sub-field
    									'value' => get_the_ID(),
    									'compare' => '='
    								),
    								array(
    									'key'		=> 'person_department_head', // this should be the second sub-field
    									'value' => true,
    									'compare' => '='
    								)
    							)
    						);
    
    						// query
    						$the_query = new WP_Query( $args );
    
    						?>
    						<?php if( $the_query->have_posts() ): ?>
    							<ul>
    							<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    								<li>
    									<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    								</li>
    							<?php endwhile; ?>
    							</ul>
    						<?php endif; ?>
    
    						<?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>
    
  • That did it, thanks! I would not have gotten that difference on the compare value.

    It sounds like the multi-post object and relationship fields are pretty much the same, but I suppose one difference is in the UI when adding/editing a particular post.

  • Ahh, so using the doctors example above….

    If I, in the Doctors custom post type, have a Post Object field, I could then use that to connect Dr. Smith to a particular location, say Melbourne.

    And then on the Melbourne post page, I could display the title and featured image of Dr. Smith?

    I have a setup simliar to the relationship-field as shown in the tutorial above, but when I switched the custom field relationship to post object (only one connection, not multiple), the same results aren’t showing up.

  • That did the trick. Thanks! That helps me be on my way with this project.

    And thanks for pointing me toward that filtering page, I’m sure that will come in handy.

Viewing 9 posts - 1 through 9 (of 9 total)