1

I'm try to create a pages counter excluding certain ID pages but the code don't work.

I'm using this code. How can I fix it? Thanks.

<?php
$count_pages = wp_count_posts('page');
echo "$count_pages->publish";
$args = array(
    'post__not_in' => array(10010),
     );
    query_posts($args);
?>
0

This should work for you to exclude via ID:

//replace the 3,8 with your page ids
<?php  $args=array(
  'post__not_in' => array(3,8),
  'post_type' => 'page',
  'post_status' => 'publish',
); 
query_posts($args); ?>

If you want to exclude via page title you can do this

<?php $exclude1 = get_page_by_title('Sample Page Title'); ?>
<?php $exclude2 = get_page_by_title('Sample Page Title 2'); ?>
<?php $args = array(    
    'post_type' => 'page',
    'order'   => 'ASC',
    'post__not_in' => array($exclude1->ID,$exclude2->ID)
    );
    query_posts($args);  ?>
| improve this answer | |
  • Thanks demo7up, but the first code display this error on my template: Call to a member function is_on_sale() on null in /home/xxxx/public_html/wp-content/plugins/woocommerce/templates/single-product/sale-flash.php – PhineasD Apr 27 '18 at 17:30
  • Did you add/change the page id's to your own? – demo7up Apr 27 '18 at 17:41
  • Yes I did it :S There's a blank space where the code would be displayed, and the error apears on the bottom of the page. – PhineasD Apr 27 '18 at 17:46
  • The error is from a plugin can you disable woocommerce and try again just to verify. – demo7up Apr 27 '18 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.