Reputation: 327
My standard query for pages is below.
$type = 'page';
$args = array (
'post_type' => $type,
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 50,
'ignore_sticky_posts'=> 1,
);
When I'm listing all pages in one page, how can I ignore woocommerce created pages like My Account, Cart, Shop...?
Upvotes: 0
Views: 172
Reputation: 327
Firstly get woocommerce page ID's
if(class_exists('WooCommerce')){
$woopages = array(get_option( 'woocommerce_shop_page_id' ),get_option( 'woocommerce_cart_page_id' ),get_option( 'woocommerce_checkout_page_id' ),get_option( 'woocommerce_pay_page_id' ),get_option( 'woocommerce_thanks_page_id' ),get_option( 'woocommerce_myaccount_page_id' ),get_option( 'woocommerce_edit_address_page_id' ),get_option( 'woocommerce_view_order_page_id' ),get_option( 'woocommerce_terms_page_id' ));
}
After that use query like this
$args = array (
'post_type' => $type,
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 50,
'post__not_in' => $woopages,
'ignore_sticky_posts'=> 1,
);
That's all!
Upvotes: 0
Reputation: 6080
You can use wordpress wp_list_pages
to display all the pages. wp_list_pages
has exclude
parameter.
So with the help of that parameter, you can exclude all the pages of woocommerce.
<?php
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url(); //To get Cart URL
$cart_id = url_to_postid( $cart_url ); //Convert that cart URL in to an ID
$checkout_url = $woocommerce->cart->get_checkout_url(); //To get Checkout URL
$checkout_id = url_to_postid( $checkout_url ); //Convert that Checkout URL in to an ID
$shop_page_id = woocommerce_get_page_id( 'shop' ); //Get an ID of shop page
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' ); //Get an ID of My account page
wp_list_pages('exclude='.$shop_page_id.','.$myaccount_page_id.','.$cart_id.','.$checkout_id.''); //To list all the pages
?>
So with the help of above code, you can print all the pages and at the same time you can ignore woocommerce pages.
Let me know if you have any doubt.
Upvotes: 1