bobbingwide / oik-types

oik custom content type manager
http://www.oik-plugins.com/oik-plugins/oik-types/
GNU General Public License v2.0
1 stars 0 forks source link

Add order by and posts_per_page for taxonomy archive queries #9

Open bobbingwide opened 7 years ago

bobbingwide commented 7 years ago

Similar to the change in 44807de, where we provide archive sort and archive posts per page fields, we now require the ability to control what happens on taxonomy archives such as "letter" and "api_letters".

The whole point of having letter selection is to find the contents quickly, so we need to be able to display quite a few per page.

bobbingwide commented 7 years ago

Workaround

The current logic in oik_types_pre_get_posts_for_archive attempts to determine the post_type for the query. This defaults to post. So for taxonomy archives we can set the archive_posts_per_page for post to be 102 ( divisible by both 2 and 3 ).

bobbingwide commented 7 years ago

The orderby still needs to be addressed. For letter taxonomies, if it's not easy to provide an admin interface in oik-types, then this may be better achieved in the implementing plugin(s).

bobbingwide commented 7 years ago

Proposed solution

For the workaround to be effective it 1. Actually needs to be implemented 2. Should produce a reasonable result on the home/ blog page. A better solution would be to detect that it's an is_tax() or is_category() query and then use the max. value for any post type associated to the taxonomy.

bobbingwide commented 6 years ago

One year on... the logic in oik_types_posts_orderby() is OK for taxonomies where we do want to display posts ordered by title, but produces unexpected results for blog posts. This was noted on WP-pompey.org.uk and has been raised as an issue in https://github.com/wppompey/wp-pompey/issues/4 for potential investigation in tomorrow's WordPress Portsmouth Meetup Clinic.

The "temporary" solution implemented in oik-types should be revisited.

bobbingwide commented 4 years ago

Many month's later. I've found three more instances where the posts are being displayed in the wrong order.

  1. On the bobbingwide.com home page, there's a section to display two most recent posts in the News category. These were being displayed in title asc, not post_date desc
  2. On the blocks.wp-a2z.org/about I used the Latest Posts block to display recent posts from Block News. This was also in the wrong order
  3. And so was the example used in the documentation for the Latest Posts block.

Explanation

The logic that tested for the value of the post type in the $query object passed to the oik_types_posts_orderby filter function assumed that if the post_type was set in the query then it wasn't a query for posts. But when the query is for a selected taxonomy term the the value of post_type is set. So we need to explicitely check that it's not post before applying our override of the $orderby.

bobbingwide commented 4 years ago

And most recently I lwas wondering why the orderby for the question CPT was by post_title ASC rather than the default. Again, it was the filter function oik_types_posts_orderby

if ( $query->is_post_type_archive() ) {
            $orderby = "$wpdb->posts.post_title asc";
        }

I'm wondering if the post_type should be tested to see if it's hierarchical ( like page ) before it changes the orderby.

So any post type which isn't hierarchical ( like post ) will continue to be sorted by post_date desc. oik_pluginversion?

bobbingwide commented 3 years ago

I rather naively raised Gutenberg issue 30237 before investigating whether or not it was one of my own plugins that was causing the problem. I've now found another instance where changing the orderby produced the wrong results. This is explained in the issue at https://github.com/WordPress/gutenberg/issues/30237#issuecomment-806744632

The fix is to change oik-types and close the GB issue as Invalid/Wontfix.

bobbingwide commented 1 year ago

My current requirement is: