• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Need help with CPT archive page

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Need help with CPT archive page

This topic is: not resolved
  • This topic has 2 replies, 2 voices, and was last updated 10 years, 2 months ago by mmjaeger.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • April 29, 2015 at 11:44 am #149526
    mmjaeger
    Member

    hello

    I was following basically some function I found over at wpsites.com but I'm struggling:

    add_action( 'pre_get_posts', 'custom_post_type_archive' );
    
    function custom_post_type_archive( $query ) {
    
    if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
    
    		$query->set( 'posts_per_page', '6' );
    		$query->set( 'orderby', 'title' );
                    $query->set( 'order', 'DESC' );
    	}
    
    }

    I want to show all posts on that page - however it always only shows the number I've set on the WP Readings Settings page?

    Second, I've a few custom fields and I'd like to sort the output based on the values of TWO fields - one being numeric and other one alpha.

    Hope somebody can help.

    Thank you in advance for your input.

    April 29, 2015 at 6:57 pm #149561
    Genesis Developer
    Member

    Replace this line

    $query->set( 'posts_per_page', '6' );

    by

    $query->set( 'nopaging', true );


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    April 29, 2015 at 7:05 pm #149562
    mmjaeger
    Member

    As to the sorting question, I kind of got it to work:

    add_action( 'pre_get_posts', 'ta_custom_post_type_archive' );
    function ta_custom_post_type_archive( $query ) {
    	
    	// do not modify queries in the admin
    	if ( is_admin() )
    		return $query;
    		
    	if ( $query->is_main_query() && is_post_type_archive( 'ta_member' ) ) {
    		
     		$query->set( 'posts_per_page', -1 );	
    		$query->set( 'meta_key', 'member_order' );
    		$query->set( 'meta_query', array(
    			array(
    				'key'	=> 'member_order',
    			),
    			array(
    				'key'	=> 'member_last_name',
    			)
    		));
    	    
    	    add_filter( 'posts_orderby', 'customorderby' );
    	    
    	    return $query;
    	    
    	}
    	
    
    }
    
    function customorderby( $orderby ) {
    	return 'mt1.meta_value+0 ASC, mt2.meta_value ASC';
    	remove_filter( 'posts_orderby', 'customorderby' );
    }
    

    didn't have a chance to check whether the code messes up anything else - where's the best place to put the add_filter... and the remove_filter...?

    Thanks again

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble