Create a gist now

Instantly share code, notes, and snippets.

Fix the [ReOrder Post Within Categories](http://wordpress.org/plugins/reorder-post-within-categories/) issue where posts are removed from the loop when updated. Note, this plugin is a bit messy to begin with, but I just needed a solution that works. I first brought up this issue in the WordPress Plugin Support Forum [here](http://wordpress.org/s…
Around line 180 of the file `reorder-posts`within`categories.php`, you should see the following:
if($taxonomie->hierarchical == 1 && is_array($orderedSettingOptions) && in_array($taxonomie->name, $orderedSettingOptions)){
//echo "<li>".$taxonomie->name."</li>";
$terms = get_terms( $taxonomie->name );
//echo "<pre>";
//print_r($terms);
//echo "</pre>";
if (count($terms) > 0){
//echo "<ul>";
foreach ($terms as $term){
$terms_of_the_post = wp_get_post_terms( $post_id, $taxonomie->name );
//echo "<li>";
//echo "<p>--" . $term->name . " (" . $term->term_id .")</p>";
if(in_array($term, $terms_of_the_post))
{
The line that reads `if(in_array($term, $terms_of_the_post))` is what's causing the issue. The object stored in $term will never match any of the objects in the array $terms_of_the_post. So I changed that code to match the following:
if($taxonomie->hierarchical == 1 && is_array($orderedSettingOptions) && in_array($taxonomie->name, $orderedSettingOptions)){
//echo "<li>".$taxonomie->name."</li>";
$terms = get_terms( $taxonomie->name );
$terms_of_the_post = wp_get_post_terms( $post_id, $taxonomie->name );
$term_ids_of_the_post = array();
foreach( $terms_of_the_post as $term_of_the_post ) {
$term_ids_of_the_post[] = $term_of_the_post->term_id;
}
//echo "<pre>";
//print_r($terms);
//echo "</pre>";
if (count($terms) > 0){
//echo "<ul>";
foreach ($terms as $term){
//echo "<li>";
//echo "<p>--" . $term->name . " (" . $term->term_id .")</p>";
if(in_array($term->term_id, $term_ids_of_the_post))
{
So instead of comparing the object $term to the array of objects in $terms_of_the_post, I created an array of the term_ids and checked if the value $term->term_id is in the array. Now when I update a post that is in a manual ordering, the post isn't removed from the end result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment