Created
August 5, 2021 02:14
-
-
Save khoipro/28cc1580ab58d8a8bff473e4ddf2c0f4 to your computer and use it in GitHub Desktop.
Extends WordPress custom post query using wp_parse_args()
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
| <?php | |
| /** | |
| * Get WP_Query object from custom arguments | |
| */ | |
| function codetot_get_post_query($custom_post_args) { | |
| $default_args = array( | |
| 'post_type' => 'post', | |
| 'posts_per_page' => get_option('posts_per_page') | |
| ); | |
| // Tương tự array_merge, nhưng nó bao gồm xử lý arguments của WordPress rồi. | |
| $post_args = wp_parse_args($custom_post_args, $default_args); | |
| return new WP_Query($post_args); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment