It doesn’t make any sense to try and pass a query result to get_page_by_path()
. The point of WP_Query
is to query for a selection of posts based on given criteria, while get_page_by_path()
is for retrieving a single specific post based on its path. There’s no reason you’d need to use them together.
If you want to delete posts based on their slug, then you don’t need a query at all:
$pages = array( 'member-login', 'member-account', 'member-register', 'member-password-lost', 'member-password-reset' );
foreach ( $pages as $slug ) {
$page = get_page_by_path( $slug );
if ( $page ) {
wp_delete_post( $page->ID, true );
}
}
Related Posts:
- WP_Query for WooCommerce Products
- How can I display recent posts from a particular category in my header?
- Using AJAX to return search form results
- Pagination is not working using WP_Query
- Two queries on the same page with pagination
- Array Chunks and Inserting Varying HTML in WP_Query
- Why is this coming back as null? Thats wrong. There is one post
- How to display future posts – modified query still yields 404
- WP_Query arguments to fetch custom post type posts which are in certain category?
- Which method is faster to get a single post?
- Import wp users via one click demo option
- How can I use $wp_query->tax_query as tax_query parameter for a new WP_Query instatiation?
- Adding column to wp_posts table or join wp_posts table with another table
- Two loops on archive page
- Check if loop has any categories?
- How to make search for posts using get method?
- Multiple filter conditions for WP_Query
- Reset WordPress Post Query to default
- What happens to the default query when I use WP_Query?
- How to Create a Random List of Child Pages
- Wp_query with 2 meta keys and array of meta values
- WP_QUERY wrong ammount of posts
- WP_Query to get post on frontpage
- How to create Page templates for showing Blog posts in different layouts?
- Writing less unnecessary code with WordPress
- How to separate two columns from one content on a page template?
- Using Ajax and WP_Query to load more posts on category page fails
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- Custom WordPress post query for displaying time-released content on website
- How to display author meta and count numbers for each user in comment.php?
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- Global page ID variable empty error
- Get posts by similar names and categories
- Second WP_Query loop shows data from main query
- active link for most recent post on vertical tabs
- Custom Theme Building & Permalinks
- WP_Query issues with argument posts_per_page
- Get author meta data with no published posts in author.php?
- How to display posts from a specific term first then another posts from another terms using tax_query
- Why ignore_sticky_posts argument is in sticky post query?
- Order by DESC, ASC in custom WP_Query
- Exclude or Include category ids in WP_Query
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- How to query for a week using key => value WP_Query argument notation?
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- How can I style future post?
- List taxonomy terms plus their latest post ordered by post date
- WordPress altering my custom query, How to fix it?
- Looping through tabular data
- How to create/modfiy WP_Query to search in post title OR custom field?
- Modifying the Search Results
- Offset Page Loops and Pagination
- How to find a post id using the post_excerpt?
- Comparing dates in custom field
- reducing the amount of wp_query calls
- Use post object from first query in second query
- meta_value_num not ordering all items
- Meta Queries – should nesting work after WP 4.1?
- Is there a better way to pull in custom content without querying posts?
- Pass $page_id to new WP_Query
- Can I modify a WP_Query instance or clone it with modifications?
- Include posts from some categories while excluding from others
- WP_Query within function within WP_Query
- Multiple Rows in a using wp_query
- How to add tax_query to $args with concatenation
- Change AJAX filter from POST to GET for URL Parameters
- When listing child pages run out of memory
- Function to retrieve IDs of posts, cache results, and improve wp_query
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Search.php – return number of results but cannot loop through
- wp query remove posts from query then update max pages and posts found
- WP_Query Orderby meta_key and hide some meta_key
- Show X taxonomies of the latest published posts
- Combine relationship posts with existing wp_query
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- What is the equivalent WP_Query of a SQL Query?
- create custom shortcode wp and put php code in
- WordPress Query custom ordering by temporary variable
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- How to get only present and past posts with post_date
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- Load WP Query with Ajax
- WPQuery loop not giving expected output
- WordPress tax_query ignoring relation OR
- pagination functions are not working
- Fetch only categorized posts
- Wrap group of wp query posts to parent div by date/year
- Continue loop after $queryObject
- Wrote a WP Cron Plugin and it triggers a fatal error upon activation
- Declare inline background image in functions.php
- Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]
- Getting Year & Date inside wpdb [duplicate]
- loop through custom post types with meta data
- Looking for a way to exclude frontpage and nav menu from query filter
- Using Query In Post Type Archives
- Get posts by meta value except one post [closed]
- Is there another way to retrieve a post_id from post_meta other than a SQL query?