Skip to content

Instantly share code, notes, and snippets.

@khoipro
Created August 5, 2021 02:14
Show Gist options
  • Select an option

  • Save khoipro/28cc1580ab58d8a8bff473e4ddf2c0f4 to your computer and use it in GitHub Desktop.

Select an option

Save khoipro/28cc1580ab58d8a8bff473e4ddf2c0f4 to your computer and use it in GitHub Desktop.
Extends WordPress custom post query using wp_parse_args()
<?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