I am creating a custom plugin which shows custom order for posts for different categories. Hereby on plugin activation i am calling a function which stores order of newly created posts as

Post Order

here meta key is as follows the integer value is the category id

Given Below is the code that how i am creating these post meta entries.

function set_post_meta_entry() {
$categories = get_categories();
foreach ($categories as $category) {
    $category_posts = get_posts(array(
        'category' => $category->term_id,
        'numberposts' => 30,

    $index = 1;
    foreach ($category_posts as $post) {
        update_post_meta($post->ID, 'test_' . $category->term_id.'_index', $index);


The thing i want is that on the category page with id 36059 should show post in this order and after this order, rest of the post should display on the basis of published date.


Your Answer

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

Browse other questions tagged or ask your own question.