Support

Account

Home Forums ACF PRO Custom post type and crossed data

Unread

Custom post type and crossed data

  • Hi, I have some little problem to show some article with a little complex acf relationship.
    I have 3 custom post types and some of them have a relation beetween them.

    Country
    – Country 01
    – Country 02
    – Country 03
    – …
    Sports
    – Sport 01
    – Sport 02
    – Sport 03
    – …
    Trial
    – Trial 01
    – Trial 02
    – Trial 03
    – …

    I want that when I am on a sport page, they show me the corresponding trial (Sport 01 -> Trial 01, Trial 11, Trial 21 …), that’s work fine with no real problem, and in this page they are also organised by category (Men Women)

    In my trial page i have some data, like a relationship field inside the repeater. The relationship let me choose, on of the country, and that’s work fine too.

    My problem is on the country page. I want to show some specific trials, that i filter with some value of the trials page (like the rank, the results…), and order them with is category, is parent … I make you a little scheme for you to understand.

    Country 01
    – First Place (value from a repeater in the trial field)
    — Sport (parent of the trial)
    — Category (Category of the trial
    —- Trial 01 (The trial where, my country is on the first place)

    I already filter the specific trial that I wanted and it works fine with

    
    function my_posts_where( $where ) {
    
        $where = str_replace("meta_key = 'resultats_%", "meta_key LIKE 'resultats_%", $where);
    
        return $where;
    }
    
    add_filter('posts_where', 'my_posts_where');
    
                // args
    $args_one = array(
        'numberposts'   => -1,
        'post_type'     => 'epreuves',
        'meta_query'    => array(
            'relation'      => 'AND',
            array(
                'key'       => 'resultats_%_rank',
                'compare'   => '=',
                'value'     => 1,
            )
            , array(
                'key'       => 'resultats_%_country',
                'compare'   => 'LIKE',
                'value' =>  get_the_ID(),
            )
        ) 
    );
    <?
    $the_query_one = new WP_Query( $args_one );
    
    ?>
    <?php if( $the_query_one->have_posts() ): ?>
        <ul>
            RANK 01
            <?php while ( $the_query_one->have_posts() ) : $the_query_one->the_post(); ?>
                <li>
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </li>
            <?php endwhile; ?>
        </ul>
    <?php endif; ?>
    
                <?php wp_reset_query(); 
    

    But no, I don’t know how to group the results by category(men/women) inside each sport (the parent custom post type) ?

    Thank you

Viewing 1 post (of 1 total)

The topic ‘Custom post type and crossed data’ is closed to new replies.