0

I have been looking for this but everyone that is posting a solution is just returning available menu items from a specific menu via

wp_get_nav_menu_items( $menu, $args );

or something similar.

What I am after is this http://prntscr.com/73oas5 in a single array.

What I am trying to do is restrict sidebars to be shown on specific pages rather than shown all the time. I have everything ready but need the list of all pages, posts, taxonomies ID's

Any help is appreciated.

2
  • 1
    Those lists on the menus dashboard page do not display "all available menu items and types" - they display all available public post types and taxonomies. Menu items are not created until a post of one variety or another is added to a menu. The question you wish to be asking is "How can I query all available public post types and taxonomies?" – bosco May 10 '15 at 20:34
  • thnx for the explanation , would you have an example of that ? – Benn May 10 '15 at 20:43
1

There are several ways to answer that question, depending on what it is you are attempting to accomplish. To generalize, you need to create two queries: one to get all public posts and one to get all public taxonomies and terms. Getting both in one array is not practical as term objects and post objects have different formats - however you can construct your own array from the two that are produced.

WordPress queries can be constructed in a number of different ways using WP_Query parameters. Alternately, various other functions perform pre-built queries for you.

In short, you are probably after something similar to (untested - may need some work):

$public_taxonomies = get_taxonomies( Array( 'public' => true ) );
$terms = get_terms( $public_taxonomies ); // Get ALL terms from all public taxonomies

$public_post_types = get_post_types( Array( 'public' => true ) );
$posts = get_posts( Array(
  'posts_per_page' => -1                  // Get ALL posts...
  'post_type'      => $public_post_types, // ...of the public post types...
  'post_status'    => 'publish'           // ...that are published.
) );

Please note that this has some pretty hefty performance implications, particularly on large sites... Returning virtually all the content on a site in one go is no small task. Better to break it up into several queries with pagination parameters, or caching just the important bits from the resulting arrays using the Transients API, if at all possible.

2
  • excellent bud , I am trying to get the ID and title so that I can restrict sidebar showing on specific pages. – Benn May 10 '15 at 22:26
  • updated the post – Benn May 10 '15 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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