1

I created like system in wordpress. And I created 'sayim_beyenme' table and created 'say_post_id' and 'total_post_likes' datas. Now I want to display my posts orderby total likes per each post. I get posts ids with array_map, but I dont know how can I order these posts by total_post_like values. For testing I have used 'title' This is my codes:

<?php

                $results = $db->prepare("SELECT say_post_id FROM sayim_beyenme ORDER BY total_post_likes DESC LIMIT 3");
                $results->execute();
                $results = $results->fetchAll();
                $like_posts = array_map(function(&$r) { return $r['say_post_id']; }, $results);

                if($like_posts) {

                    $postlar = new WP_Query(array(
                        'paged' => get_query_var('paged', 1),
                        'post_type' => array('post'),
                        'posts_per_page' => 9,
                        'post__in'      => $like_posts,
                        'orderby' => 'title',
                        'order' => 'ASC',
                    ));

2 Answers 2

0

I found my answer, I added 'orderby' => 'post__in'

0

You can't directly, instead you'll need to figure that out yourself then provide the sort order manually to WP_Query and specify post__in as the orderby value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.