I have been trying different things to get this to work but I have failed. The website is a tutoring website. Tutors teach different subject. There is a page where all the tutors will be listed and pages where they are listed by subject(math, biology, physics, biology).
I created a repeater custom field for team members(tutors). This repeater field has an image, name, and biographical field. All this info shows up on the About page.
<?php // ACF fields if(have_rows('team_member')): ?> <?php while(have_rows('team_member')): the_row(); ?> <?php // create variables // $image = get_sub_field('team_member_image'); // $photo = $image['sizes']['thumbnail']; ?> <div class="col-md-6 tutor"> <?php $image = get_sub_field('team_member_image'); $size = 'team-member'; $alt = $image['alt']; $url = $image['url']; if( !empty( $image ) ): ?> <div class="image-container"> <img class="img-fluid" src="<?php echo esc_url( $url); ?>" alt="<?php echo esc_attr($alt); ?>" /> <?php endif; ?> </div> <h3><?php the_sub_field('team_member_name'); ?></h3> <?php the_sub_field('team_member_bio'); ?> </div><!-- end col --> <?php endwhile; ?> <?php endif; ?>
I also created a checkbox selection in the repeater field for the 4 subjects(some tutors teach more than one. I created a page for each of the 4 subjects. What I’m trying to do is, if the admin goes to the about page and adds a tutor and the subject(s) they teach, it will post on a subject page as well as the about page. So if a tutor teaches math and physics, the data will post to the About page, Math Tutors page, and Physics Tutors page. I’m trying to come up with a conditional statement on each page but can’t figure it out. Would I put a conditional statement inside the if(have_rows(team_member)?
In my research, I read that you can’t do a new WP_Quey using repeater fields so I created a custom post type using the same ACF fields. The problem is on my ‘Biology’ page for example, I have two tutors who teach biology and that is checked in the backend but on the front end only one tutor shows. I’m using this query to get tutors who are checked for biology
$args = array( 'post_per_page' => 10, 'post_type' => 'pg-tutor', 'meta_query' => array( array( 'key' => 'subject', 'value' => 'biology', 'compare' => 'LIKE', ), ) );
Any suggestions are appreciated.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.