Community Forums › Forums › Archived Forums › Design Tips and Tricks › posts sorted with custom fields – pagination problem
Tagged: custom field, orderby, pagination, sort
- This topic has 3 replies, 2 voices, and was last updated 8 years, 7 months ago by cyanoorange.
-
AuthorPosts
-
February 12, 2016 at 9:43 am #178892cyanoorangeParticipant
Hi,
I posted a more complex question to this topic before. Now I try to keep it more simple, hoping someone could help me.
On my page I want my posts be sorted by a custom field "kosmo_sortier_nr":add_action('genesis_before_loop','sortierung_Kosmo'); function sortierung_Kosmo(){ $aktion = filter_input(INPUT_GET, 'aktion', FILTER_SANITIZE_STRING); if($aktion!=2 && is_home()){ $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; query_posts('paged=' . $paged . '&posts_per_page=5&meta_key=kosmo_sortier_nr&meta_compare=<=&meta_value_nr&orderby=meta_value&order=ASC'); } }
What happens is: the first 3 pages appear correctly, the following pages show 404.
http://kleinekosmonautin.de/wordpress/
Is anybody able to help me with this? What am I doing wrong?
Would be really great!February 12, 2016 at 10:37 am #178902Genesis DeveloperMemberYou can try this once
add_action('genesis_before_loop','sortierung_Kosmo'); function sortierung_Kosmo(){ $aktion = filter_input(INPUT_GET, 'aktion', FILTER_SANITIZE_STRING); if($aktion!=2 && is_home()){ $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $args = array( 'paged' => $paged, 'posts_per_page' => 5, 'meta_key' => 'kosmo_sortier_nr', 'meta_compare' => '<=', 'meta_value_nr' => '', 'orderby' => 'meta_value', 'order' => 'ASC' ); genesis_custom_loop( $args ); } }
February 12, 2016 at 10:55 am #178905cyanoorangeParticipantFirst of all: thanks for trying to help. I changed the code, but it doesnt work. You can see the result right now on the site.
Would be great, if you would have another idea.February 13, 2016 at 5:51 am #178955cyanoorangeParticipantI found a solution - the "custom-loop-hint" was important. Thanks for that.
My solution now is to change the whole loop. But I have the feeling, that this might be not a "best-way-to-do-it" solution. My script now makes the following things possible: Sort post with custom field, sort them via click ASC and DSCN, showing pages.
Would be great if anybody could give me feedback.
Here is the important part of the functions.phpremove_action( 'genesis_loop', 'genesis_do_loop' ); remove_action( 'genesis_loop', 'prefix_do_loop' ); add_action('genesis_loop','sortierung_Kosmo'); function sortierung_Kosmo(){ /*checkt ob es per Klick auf link eine Aktion gab*/ $aktion = filter_input(INPUT_GET, 'aktion', FILTER_SANITIZE_STRING); /*alte posts zuerst*/ if($aktion!=2 && is_home()){ $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $args = array( 'paged' => $paged, 'posts_per_page' => 5, 'meta_key' => 'kosmo_sortier_nr', // 'meta_compare' => '<=', 'meta_value_nr' => '', 'orderby' => 'meta_value', 'order' => 'ASC' ); genesis_custom_loop( $args ); /*neue posts zuerst*/ }else if($aktion==2 && is_home()){ $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $args = array( 'paged' => $paged, 'posts_per_page' => 5, 'meta_key' => 'kosmo_sortier_nr', 'meta_value_nr' => '', 'orderby' => 'meta_value', 'order' => 'DSCN' ); genesis_custom_loop( $args ); }else{ if ( is_page_template( 'page_blog.php' ) ) { $include = genesis_get_option( 'blog_cat' ); $exclude = genesis_get_option( 'blog_cat_exclude' ) ? explode( ',', str_replace( ' ', '', genesis_get_option( 'blog_cat_exclude' ) ) ) : ''; $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; //* Easter Egg $query_args = wp_parse_args( genesis_get_custom_field( 'query_args' ), array( 'cat' => $include, 'category__not_in' => $exclude, 'showposts' => genesis_get_option( 'blog_cat_num' ), 'paged' => $paged, ) ); genesis_custom_loop( $query_args ); } else { genesis_standard_loop(); } } }
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.