Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action get_more_posts returning empty values #27

Open
marcovieira17s opened this issue Feb 3, 2023 · 4 comments
Open

Action get_more_posts returning empty values #27

marcovieira17s opened this issue Feb 3, 2023 · 4 comments
Assignees
Labels

Comments

@marcovieira17s
Copy link

I dont know if that error is because i use WPML but $this->_get_order returned with duplicated IDs and Admin Ajax action "get_more_posts" was returning empty values so i fixed the function and works fine now.

https://github.com/aurovrata/ReOrder-posts-within-categories/blob/master/admin/class-reorder-post-within-categories-admin.php

	private function _get_ranked_posts($post_type, $term_id, $start, $offset){
		$results = array();
		$ranking = $this->_get_order($post_type, $term_id, $start, $offset);
    $posts = get_posts(array(
			'post_status'=>'any',
      'post_type' => $post_type,
      'post__in'=>$ranking,
      'ignore_sticky_posts'=>false,
      'posts_per_page'=>-1
    ));
    foreach($posts as $post) {
			$img = self::get_thumbnail_url($post);
			$rank = array_search($post->ID, $ranking);
      $results[(int)$rank]=array(
				'id'=>$post->ID,
        'link'=>admin_url('post.php?post='.$post->ID.'&action=edit'),
        'img'=> $img,
				'status'=>$post->post_status,
        'title'=>apply_filters('reorder_posts_within_category_card_text',get_the_title($post), $post, $term_id)
      );
    }

		ksort($results);
		return $results;
	}
@aurovrata
Copy link
Owner

Hey Marco!

thanks so much for the contribution, I will go through this and add it the next release. Next time, feel free to do a Pull Request so I can merge it more easily.

@aurovrata aurovrata self-assigned this Feb 3, 2023
@aurovrata aurovrata added the bug label Feb 3, 2023
@marcovieira17s
Copy link
Author

marcovieira17s commented Feb 3, 2023

sorry, i dont know use the github features very well... i was tried to do a pull request but i cant because you only have 1 branch.
image

@aurovrata
Copy link
Owner

$this->_get_order returned with duplicated IDs

this is likely because WPML tags translation post IDs with the same taxonomy term ID that is being ranked, and hence the current function returns posts IDs of translated posts too.

the post query get_posts is likely being filtered by WPML for a given locale and therefore only the posts belonging to that translation. While the _get_order() uses SQL queries which do not get filtered by WPML and returns all the post IDs for that term.

instead of sorting out the results with ksort() I think it's more efficient to populate the results with only the posts found by the query get_posts().

v2.14.1 has this fix. Can you test it on your server and let me know if it solves your problem?

@marcovieira17s
Copy link
Author

Works fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants