Community Forums › Forums › Archived Forums › General Discussion › 'orderby' and 'order' ingored in genesis_custom_loop
Tagged: genesis_custom_loop
- This topic has 7 replies, 2 voices, and was last updated 9 years, 4 months ago by Brad Dalton.
-
AuthorPosts
-
August 20, 2015 at 1:51 pm #163037lagomdesignMember
I'm adding a custom loop to the end of a specific page (using a page template). The custom loop pulls all the posts from a custom post type. For testing purposes, my args are set up like this:
$args = array( 'post_type' => 'rh_community', 'posts_per_page' => -1, 'orderby' => 'rand' );
When usinggenesis_custom_loop( $args )
, the posts are returned in the same order regardless as to what 'orderby' is set to. Makes absolutely no difference.I tested my set up using the same
$args
variable withget_posts( $args )
. That worked exactly as expected.Is this a known issue? Any way around it?
http://rh2.lagomdesign.net/where-we-build/print( '<div class="communities">' ); genesis_custom_loop( $args ); print( '</div>' ); print( '<div class="communities">' ); $comms = get_posts( $args ); print( '<ul>'); foreach( $comms as $com ) { printf('<li>%s</li>', apply_filters('the_title', $com->post_title ) ); } print( '</ul>' ); print( '</div>' );
August 20, 2015 at 2:05 pm #163039Brad DaltonParticipantCan you post all the code for the custom loop please.
Also, why are you using print instead of echo?
August 20, 2015 at 2:09 pm #163041lagomdesignMemberI think print() looks better in the code. No difference in performance.
Here's the relevant part of the page template.
//* Add custom loop to list all Communities add_action( 'genesis_after_loop', 'foundation_do_community_loop', 11 ); function foundation_do_community_loop() { //* Remove floorplan filter remove_action( 'genesis_after_entry', 'foundation_community_filter' ); $args = array( 'post_type' => 'rh_community', 'posts_per_page' => 10, 'orderby' => 'rand' ); //* Add column classes add_filter( 'post_class', 'foundation_loop_classes' ); //* Remove the entry meta in the entry header remove_action( 'genesis_entry_header', 'genesis_post_info', 5 ); //* Add the featured image before post entry add_action( 'genesis_entry_header', 'foundation_community_image', 5 ); //* Add extra info after the title add_action( 'genesis_entry_header', 'foundation_community_info', 12 ); //* Add permalink button after entry add_action( 'genesis_entry_content', 'foundation_permalink_button', 15 ); //* Remove the entry meta in the entry footer remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); print( '<div class="communities">' ); genesis_custom_loop( $args ); print( '</div>' ); print( '<div class="communities">' ); $comms = get_posts( $args ); print( '<ul>'); foreach( $comms as $com ) { printf('<li>%s</li>', apply_filters('the_title', $com->post_title ) ); } print( '</ul>' ); print( '</div>' ); }
August 20, 2015 at 2:43 pm #163042Brad DaltonParticipantTested and works.
<script src="https://gist.github.com/braddalton/3682be9dcc6d3ba32ea0.js"></script>
https://gist.github.com/braddalton/3682be9dcc6d3ba32ea0
August 20, 2015 at 2:53 pm #163043Brad DaltonParticipantI removed some of your actions because the code wasn't included making them causes errors.
August 20, 2015 at 3:19 pm #163045lagomdesignMemberThanks for you work, brad.
There must be something else in my code somewhere, 'cause that still ain't working. I'm going to have to start parsing thru other files to make sure there's no filters at work that I don't know about.
August 20, 2015 at 3:32 pm #163046lagomdesignMemberFound it.
Sorry for the trouble, and thanks again for the work!
By the way … is there a reason to use echo over print?
August 20, 2015 at 4:40 pm #163049Brad DaltonParticipantYes but i forget why! hahaha. Will post back here when i remember.
I don't think its a huge deal but haven't seen print used before so you're coding is unique!
I did change the post type as i tested on Exec Pro so i guess you picked that up.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.