• I have a unique use case for this plugin, I believe. I am using it to allow users to favorite a custom post type but also I am using it to allow them to favorite different advanced custom field elements within the page. The former works fine, the latter I have questions about.

    There are two fields in a single repeater field, Question and Answer. I am able to get a unique like button for each Q&A through:
    echo do_shortcode('[wp_ulike for="comment" id="'. $post_id .''. $qaid .'"]');
    where $qaid is an integer unique to each Q&A down the page and then post ID keeps it unique to that interview page.

    What I need now is to display the most popular Q&A’s throughout all interviews. This works fine for the most popular posts (interviews).

    I am able to get all Q&A’s to list on a single page through php but it does not sort by likes.

            $answer_query = new WP_Query(
            array(  
                $post__in = wp_ulike_get_popular_items_ids(array(
                    'type'   => 'comment',
                    'status' => 'like',
                    'period' => 'all',
                    'is_normal' => 'false',
                    'limit'  => '5'
                )),     
                'posts_per_page' => -1,
                'post__in' => $post__in,
                'post_type' => 'interview',
                'orderby' => 'post__in',
                'order' => 'DESC'
                )
            ); 
    
            while ($answer_query->have_posts()): $answer_query->the_post();
            if( have_rows('interview') ):
              while( have_rows ('interview') ): the_row();
                // Questions and Answers
                  if( get_sub_field('question')){
                    $question = get_sub_field('question');
                  }
                  if( get_sub_field('answer')){
                    $answer = get_sub_field('answer');
                  }
                  if( get_sub_field('qaid')){
                    $qaid = get_sub_field('qaid');
                  }
                  $post_id = get_the_ID();
            echo '<div class="question_container">';
            echo '<div class="question"><h3>' . $question . '</h3></div>';
            echo do_shortcode('[wp_ulike id="'. $post_id .''. $qaid .'"]');
            echo '<div class="answer">' . $answer . '</div>';
            echo '</div>';
            endwhile; 
            endif;
            endwhile;
    
            wp_reset_postdata();
    • This topic was modified 3 years, 7 months ago by weihs5.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Sorting ACF repeater fields by WP ULike popularity’ is closed to new replies.