1

I'm using a plugin called CMS Page Order http://wordpress.org/extend/plugins/cms-page-order/ (Now referred to as CPO)

It's pretty simple, the said plugin adds a new item to the submenu of every custom post type. The menu item leads to a page where you can reorder the posts of the certain post type.

I've added so that you can create new posts directly from this view, so basically it's like the default edit post view in Wordpress, but you can reorder your posts aswell. This renders the usual post edit page pretty useless.

So my question is, is there a way for me to remove the "All post type's" submenu item (edit.php?post_type=nameofposttype) replacing it with this menu item created by CPO while also making the top level menu item itself point to the page created by CPO.

–––

What I've been trying to do is to try to replace the top level menu item with the URL of the submenu item created by CPO using the plugin Admin Menu Editor, but changing the URL via the plugin is not allowed it seems. I then tried moving the CPO menu item to the top of the submenu as I noticed that the top level menu item points to the topmost submenu item (ie "All pages/posts"). That did not work either, as it produces an URL that is erroneous (it makes the top level menu item point to admin.php?page=order-xxx)

Here's some images to further explain what I mean. Here's how the top level item regurlarly behaves

Here's how the top level item behaves as default (edit.php?post_type=xxx)

Now here's what happens if I move my page with the special menu handler to the top. The top level item gets a new URL, but it's erroneous

Now here's what happens if I move my page with the special menu handler to the top. The top level item gets a new URL, but it's erroneous (admin.php?page=order-xxx)

Here's the url that the special menu handler page has, the URL that the top level menu item should have

Here's the URL that the special menu handler page has, the URL that the top level menu item should have (edit.php?post_type=xxx&page=order-xxx)

So, how can I change the top level menu item to the URL I want?

2
  • Could you rephrase your question? I simply don't understand a) What's wrong b) What you're trying to get.
    – kaiser
    Sep 29, 2012 at 17:16
  • @kaiser I elaborated now, still feels kind of fuzzy to me aswell. I'm not sure I've got the right approach.
    – INT
    Sep 29, 2012 at 19:18

3 Answers 3

3

You can also change the menu with the global variables of WordPress for display the menu and submenu. All first items are in the var $menu and all suparts are in $submenu.

Also a small example for change the order of the submenu-items with edit.php. Add thius plugin and see the result via debugging. The function fb_cmp is only the logic for reorder, but you can define you custom order in this function, she is the callback for usort.

<?php
/**
 * Plugin Name: .my Tests
 * Plugin URI:  http://bueltge.de/
 * Description: 
 * Version:     0.0.1
 */

add_action( 'admin_init', 'fb_get_menu' );
function fb_get_menu() {
    global $menu, $submenu;

    var_dump( $submenu['edit.php'] );
    usort( $submenu['edit.php'], 'fb_cmp' );
    echo '<hr>';
    var_dump( $submenu['edit.php'] );
}

function fb_cmp( $a, $b ) {

    if ($a->value == $b->value)
        return 0;
    else
        return $a->value < $b->value ? 1 : -1; // reverse order
}

As hint the result in a screenshot. enter image description here

1

have you tried considering jquery? Maybe this will help you. Ive tried it and it worked. Just put this in your functions.php

add_action('admin_footer', 'change_post_url');
function change_post_url(){
?>
<script>
    jQuery(document).ready(function($){         
        $(".anchor_class_name").attr("href","sample.php");
    });
</script>
<?php
}
2
  • That might be a way if there's no other way to do it. I tend to try to rely on jQuery as little as possible in situations like this.
    – INT
    Oct 10, 2012 at 7:52
  • yah I just also use it when theres no more options left but sometimes in order to save time jQuery is a way to go :)
    – loQ
    Oct 10, 2012 at 8:34
0

Afaik, you can simply use add_query_arg( 'key', 'value' ); when registering the page.

I explained the details of the WordPress admin menu system in this blog article. Can't post this hear as it's much too much and mucho too much.

2
  • I'm not entirely sure how I can use this to make clicking "Livsmedel" behave like you just clicked "New Sortable Menu". I just want to replace the regular view where pages and posts are listed, with my custom page and have it behave like it would do normally with the submenu getting highlighted when top level menu item is clicked/active.
    – INT
    Oct 12, 2012 at 21:31
  • @INT See update and link.
    – kaiser
    Oct 16, 2012 at 22:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.