Last active
June 15, 2018 10:57
-
-
Save kierzniak/42b119043a95f8ba7b6aff7dbb26992e to your computer and use it in GitHub Desktop.
Revisions
-
kierzniak revised this gist
Jun 15, 2018 . No changes.There are no files selected for viewing
-
kierzniak revised this gist
Jun 15, 2018 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,9 @@ function motivast_wp_query() { new WP_Query(array( /** * This line will not modify your query but we can use it to * identify query later `$wp_query->get('orderby') === 'custom'`. */ 'orderby' => 'custom' )); } @@ -24,17 +24,17 @@ function motivast_wp_query() { * * @return string */ function motivast_orderby_custom_column( $orderby, $wp_query ) { /** * If WP_Query has `custom` as orderby parameter replace SQL */ if( $wp_query->get('orderby') === 'custom' ) { return 'wp_posts.custom DESC'; } return $orderby; } add_filter( 'posts_orderby', 'motivast_orderby_custom_column', 10, 2 ); -
kierzniak revised this gist
Jun 13, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,8 @@ function motivast_wp_query() { new WP_Query(array( /** * This line will not modify your query but we can use it to * identify query later `$wp_query->get('order_by') === 'custom'`. */ 'order_by' => 'custom' )); -
kierzniak revised this gist
Jun 13, 2018 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,10 @@ function motivast_wp_query() { new WP_Query(array( /** * This line will not modify your query but we can use to identify * query later `$wp_query->get('order_by') === 'custom'`. */ 'order_by' => 'custom' )); } -
kierzniak revised this gist
Jun 13, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,6 @@ function motivast_wp_query() { /** * Filters the ORDER BY clause of the query. * * @param string $orderby The ORDER BY clause of the query. * @param WP_Query $wp_query The WP_Query instance (passed by reference). * -
kierzniak created this gist
Jun 13, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ <?php /** * Make sample fake query to show working example */ function motivast_wp_query() { new WP_Query(array( 'order_by' => 'custom' )); } add_action( 'wp', 'motivast_wp_query' ); /** * Filters the ORDER BY clause of the query. * * @since 1.5.1 * * @param string $orderby The ORDER BY clause of the query. * @param WP_Query $wp_query The WP_Query instance (passed by reference). * * @return string */ function motivast_order_by_custom_column( $orderby, $wp_query ) { /** * If WP_Query has `custom` as order_by parameter replace SQL */ if( $wp_query->get('order_by') === 'custom' ) { return 'wp_posts.custom DESC'; } return $orderby; } add_filter( 'posts_orderby', 'motivast_order_by_custom_column', 10, 2 );