Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

List all posts of a given post type in the section #146

Open
danielbachhuber opened this issue May 25, 2016 · 7 comments
Open

List all posts of a given post type in the section #146

danielbachhuber opened this issue May 25, 2016 · 7 comments

Comments

@danielbachhuber
Copy link
Contributor

For smaller sites, where there are a limited number of total pages, it would be nice if a developer could easily customize this plugin to always list all posts of a given post type in the post type's section.

@danielbachhuber
Copy link
Contributor Author

danielbachhuber commented May 25, 2016

As it turns out, this is pretty easy to do by just creating a WP_Query somewhere in the page load:

add_action( 'wp_footer', function(){
    if ( ! is_customize_preview() ) {
        return;
    }
    // Trick the Customizer into thinking we're looking at all pages and services
    new \WP_Query( array(
        'post_type'       => array( 'page', 'service' ),
        'posts_per_page'  => 100,
        'post_status'     => 'publish',
    ));
});

@danielbachhuber
Copy link
Contributor Author

One last note: performing this action on wp_head will give you control over the order in which the sections appear.

@westonruter
Copy link
Contributor

westonruter commented May 25, 2016

@danielbachhuber really great tips, thanks! And you're right, we do need to be listing out all posts/pages regardless of whether they are currently displayed in the preview. With the introduction of the new View link this would be especially relevant, since you could open a post/page section in the Customizer and then click View to navigate there:

customize__wordpress_develop_ _just_another_wordpress_site_

Another important reason for listing all posts/pages is a drag & drop interface for changing the menu_order: #32 The posts need to be listed in order of their menu_order if they support page-attributes (or rather, a proposed x-orderable).

The unexpected ordering of the post sections that appear in the Customizer panel was also raised by @ahmadawais in #124

This has come up recently in relation to widget sidebars as well, #36922.

@celloexpressions
Copy link

I imagine we'll take a broader look at the overall UI eventually, but I'll note for now that it might be better to avoid doing a panel for posts and pages, and only show the active post section on singular views. Otherwise we'll eventually end up building the add-menu-item UI all over again... and I imagine we'll come up with a way to merge those eventually. If you can navigate the site both in the preview and in the pane, there's an experience split. In the live preview context, I imagine it would make more sense to keep most content navigation in the preview.

@westonruter
Copy link
Contributor

@celloexpressions there needs to be multiple posts active in the Customizer at a time—multiple post sections accessible for any given previewed URL—because a post type may not have a singular view and also posts may need to be previewed in the context of a subquery where they are listed on another post's singular view.

@westonruter
Copy link
Contributor

The key pieces to solve this issue (List all posts of a given post type in the section) are implemented now in #196. The solution is to introduce a Select2 for looking up a post to lazy-load the post/postmeta settings, create the section, and then open the section and navigate to the post in the preview (if it is not among the posts queried).

Other enhancements out of scope of that PR include:

  • Implement pagination, probably in the form of infinite scroll à la Select2.
  • Lazy-load first page of posts of a given type when the panel is expanded (avoiding adding additional time to load the Customizer up front).
  • Allow a post section to be added with only a subset of post data, with additional data fetched when the section is expanded.
  • Allow for the ordering of the post sections to be changed in the same way a post list table allows sorting? Different post types could have different default sorts.

@westonruter
Copy link
Contributor

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

No branches or pull requests

3 participants