Support

Account

Home Forums General Issues Post details on different page based on checkbox selection

Solved

Post details on different page based on checkbox selection

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

  • …I’m too tired. Friggin typo ‘subject’ should be ‘subjects’ 4 hours of my life I’ll never get back!!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.