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

Insert new posts at given position #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justsanjit
Copy link

There was a use case where I needed to insert new posts at a specific position within the order. Upon researching, I found a relevant discussion on the WordPress forum. The current implementation did not support this feature, so I decided to implement it based on the forum discussion.

This PR introduces a new filter reorder_post_within_categories_new_post_position. This filter is an enhancement of the existing reorder_post_within_categories_new_post_first filter, providing additional functionality to support positive and negative integer values for positioning new posts.

add_filter('reorder_post_within_categories_new_post_position', 'rank_new_posts', 10, 3);
function rank_new_posts($is_first, $post, $term_id){
    return 3;
}
  • If the filter returns a positive value, the new post will be inserted at the specified position.
  • If the filter returns a negative value, the new post will be inserted counting from the end of the array.
  • If the filter returns a null value, the ranking will default to the behavior of the reorder_post_within_categories_new_post_first filter.

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

Successfully merging this pull request may close these issues.

1 participant