You could modify the plugin, specifically the function getRelatedPosts in /plugins/related_posts/related_posts.php: Code: public function getRelatedPosts($h, $search_terms = '', $num_posts = 10) { //if (!isset($h->vars['select'])) { return false; } $h->vars['filter']['post_archived != %s'] = 'Y'; $h->vars['filter']['post_id != %d'] = $h->post->id; $h->vars['filter']['post_type = %s'] = 'news'; if ($h->version > '1.6.6') { $prepared_search = $h->prepareSearchFilter($h, $search_terms); } else { if (!$h->isActive('search')) { return false; } require_once(PLUGINS . 'search/search.php'); $search = new Search(); $prepared_search = $search->prepareSearchFilter($h, $search_terms); } extract($prepared_search); $prepared_filter = $h->db->select($h, array($h->vars['select']), 'posts', $h->vars['filter'], $h->vars['orderby'], $num_posts, false, true); $results = $h->db->getData($h, 'posts', $prepared_filter); return $results; } Effectively, you'd probably want to add a filter after line 233 that looked something like this (assuming you set the $post_author you wanted somewhere else): Code: $h->vars['filter']['post_author = %d'] = $post_author;
I changed the line 233, have disappeared the post and instead nothing is displayed. I also noticed that related posts are not working correctly, I can`t change the number of posts in the admin panel in default shows 5 posts but if I change the number, I still get the 5 posts in display posts field, and at the end of the post I receive more than 10 posts, although admin panel is set to show only 5 posts.
It's all because of the wrong order of plug-ins. As full of reason gravatar plugin and category plugin in itself change their order.
I tried a different setting Hotaru change line 233 in the plugin related posts and still not getting the author of the posts..
No, you can't change line 233 as the query needs that filter. You'd have to add an additional filter after line 233. Sorry, if I wasn't clear about that. So, for example, if you replace line 233 with these two lines: Code: $h->vars['filter']['post_type = %s'] = 'news'; $h->vars['filter']['post_author = %d'] = 1; ...it will add a filter of post_author to the related_posts query and only show you related posts that are posted by the admin (who is usually user_id = 1).
Odd. I just tested it in my base build and it worked. Could it be that you don't have any related posts by user #1? Maybe try a different user_id?
I added the posts of other users by adding the same tags for posts from different users and still get related posts from different users.
On line 245 of related_posts.php, can you add the following code and post what prints please? Code: print_r($prepared_filter);exit;
Code: Array ( [0] => SELECT *, MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s) AS relevance FROM hotaru_posts AS P LEFT OUTER JOIN hotaru_users AS U ON P.post_author = U.user_id WHERE post_archived != %s AND post_id != %d AND post_type = %s AND post_author = %d AND (post_status = %s OR post_status = %s) AND MATCH (post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT 1 [1] => youtube [2] => Y [3] => 10 [4] => news [5] => 1 [6] => top [7] => new [8] => youtube )
That is consistent with what's in my build Let's take a look at the SQL query. Remove the print statement on line 245 that you just added and please add these 2 lines in place of line 269 in /libs/Database.php: Code: $query = $h->db->prepare($this->prepare_array); if (strpos($this->prepare_array[0], 'SELECT *, MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s) AS relevance') !== false) { print_r($query);exit; } Then post here what it prints. Assuming the relevant post tag it's looking for (as in your above example) is youtube, it should print something like this: Code: SELECT *, MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST ('youtube') AS relevance FROM hotaru_posts AS P LEFT OUTER JOIN hotaru_users AS U ON P.post_author = U.user_id WHERE post_archived != 'Y' AND post_id != 1 AND post_type = 'news' AND post_author = 1 AND (post_status = 'top' OR post_status = 'new') AND MATCH (post_title, post_domain, post_url, post_content, post_tags) AGAINST ('youtube' IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT 5 You can then take what it posts and go directly into your database to run that query. You should get the same results as you would have gotten in related posts. From there, if you change the number in the post_author, you should get different results, and none where the post_author = 1. If you do get results that include post_author = 1, then the problem is elsewhere.
Code: SELECT *, MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST ('youtube') AS relevance FROM hotaru_posts AS P LEFT OUTER JOIN hotaru_users AS U ON P.post_author = U.user_id WHERE post_archived != 'Y' AND post_id != 10 AND post_type = 'news' AND post_author = 1 AND (post_status = 'top' OR post_status = 'new') AND MATCH (post_title, post_domain, post_url, post_content, post_tags) AGAINST ('youtube' IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT 2 I ran this query and got two posts by the user with id 1.
Great. Now, if you remove this line: Code: if (strpos($this->prepare_array[0], 'SELECT *, MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s) AS relevance') !== false) { print_r($query);exit; } ...do you get the same 2 posts from related_posts?
I assume that this code works only for user id 1 as the other user, I still get the related posts by the user with id 1.
Yes. I was using it as an example. You can set it to whatever user_id you'd like. For example, if you wanted to show only related posts for the particular author of the post the user is currently looking at, you would change the filter from: Code: $h->vars['filter']['post_author = %d'] = 1; to: Code: $h->vars['filter']['post_author = %d'] = $h->post->author; What is it you want to do?