custom category page does not respect ReOrder of posts
-
I’ve been trying to get the “ReOrder Posts within Categories” plugin to work in custom category pages. My efforts were complicated by bug #11 which I duly reported, and @aurovrata has now fixed in v. 2.4.2. Well and good, but my problem, it turns out, did not stem from that issue. I found that I had some code in my child-theme functions.php file that was intended to make Modern Tribe’s “Events Calendar” plugin make use of the regular posts categories. That code:
function wpa_categories_for_events(){ register_taxonomy_for_object_type( 'category', 'tribe_events' ); //register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'wpa_categories_for_events' ); function wpa_events_on_category_pages( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( 'post_type', array( 'post', 'tribe_events' ) ); } } add_action( 'pre_get_posts', 'wpa_events_on_category_pages' );
was interfering with the operations of the “ReOrder Posts” plugin. Once I removed the offending code, the “ReOrder Posts” plugin functioned fine (hooray!); however, it functions only on stock category pages generated by WP.
I have made several custom category pages. I started with the archive.php file in the twentyseventeen theme. I added a header image and some fixed text at the top, and then the loop populates the page with the relevant posts (an example is linked). I named these files category-category-slug.php as recommended, and now requests for (for example) https://williamcoulterguitar.com/category/bill-brian/ will invoke my custom page. (the php for that modified archive page is appended below) This is very much “monkey see, monkey do” programming. My acquaintance with the WP codebase and PHP is pretty shallow. I’m just fumbling around, learning as I go.
Unfortunately, the order of posts on these modified archive pages is not affected by the operation of the ReOrder plugin. My question (for the unlikely few who are still reading this tldr ramble) is this: is there any way to modify these custom archive pages such that they will respect the ordering of posts as imposed by the ReOrder plugin?
<?php /** * The template for displaying archive pages * * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/ * * @package WordPress * @subpackage Twenty_Seventeen * @since 1.0 * @version 1.0 */ add_filter( 'posts_orderby' , 'custom_cpt_order' ); function custom_cpt_order( $orderby ) { global $wpdb; // Check if the query is for an archive if ( is_archive() && get_query_var("post_type") == "my_custom_post_type" ) { // Query was for archive, then set order return "$wpdb->posts.post_title ASC"; } return $orderby; } get_header(); ?> <div class="single-featured-image-header"> <!--<img image parameters, src etc. >--> </div> <div class="wrap"> <?php if ( have_posts() ) : ?> <header class="page-header"> <?php the_archive_title( '<h1 class="page-title">', '</h1>' ); the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?> </header><!-- .page-header --> <?php endif; ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <div class="category-top-matter"> <!-- descriptive text --> </div> <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ while ( have_posts() ) : the_post(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'template-parts/post/content', get_post_format() ); endwhile; the_posts_pagination( array( 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>', 'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>', ) ); else : get_template_part( 'template-parts/post/content', 'none' ); endif; ?> </main><!-- #main --> </div><!-- #primary --> <?php get_sidebar(); ?> </div><!-- .wrap --> <?php get_footer();
The page I need help with: [log in to see the link]
- The topic ‘custom category page does not respect ReOrder of posts’ is closed to new replies.