Skip to content

Instantly share code, notes, and snippets.

@bichotll
Created September 20, 2014 10:56
Show Gist options
  • Save bichotll/7228cb9a98d1a5a381ee to your computer and use it in GitHub Desktop.
Save bichotll/7228cb9a98d1a5a381ee to your computer and use it in GitHub Desktop.
Get X posts by custom type
<?php
//show just X posts for custome type
function modify_num_posts_for_clients($query) {
if ($query->is_main_query() && $query->is_post_type_archive('client') && !is_admin()) {
$query->set('posts_per_page', -1);
}
}
add_action('pre_get_posts', 'modify_num_posts_for_clients');
function modify_num_posts_for_faq($query) {
if ($query->is_main_query() && $query->is_post_type_archive('faq') && !is_admin()) {
$query->set('posts_per_page', 20);
}
}
add_action('pre_get_posts', 'modify_num_posts_for_faq');
function modify_num_posts_for_company_opinion($query) {
if ($query->is_main_query() && $query->is_post_type_archive('company_opinion') && !is_admin()) {
$query->set('posts_per_page', 10);
}
}
add_action('pre_get_posts', 'modify_num_posts_for_faq');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment