Created
July 17, 2015 20:53
-
-
Save saxap/fe81b914880b8bfb6d62 to your computer and use it in GitHub Desktop.
show first post by id wordpress (custom order by)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //in function.php | |
| function filter_orderby_sticky( $order = '' ) { | |
| global $wpdb; | |
| //$first = pods('pods settings'); | |
| //$first = (int)$first->field( 'name of field' ); // if pods | |
| return '('.$wpdb->prefix.'posts.ID = '.$first.') DESC, '.$wpdb->prefix.'posts.post_date DESC'; // $first is id of first post | |
| } | |
| // custom wp_query | |
| add_filter( 'posts_orderby', 'filter_orderby_sticky' ); | |
| $query = new WP_Query('post_type=blabla&posts_per_page=99); | |
| remove_filter( 'posts_orderby', 'filter_orderby_sticky' ); | |
| // archive of custom posts, add in function.php | |
| add_action('pre_get_posts','filter_orderby_archive_stiky'); | |
| function filter_orderby_archive_stiky(){ | |
| if ( is_post_type_archive('CUSTOMPOSTSNAME') ) { | |
| add_filter( 'posts_orderby', 'filter_orderby_sticky' ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment