OK, so what we want to achieve is to write a function that will take a title of a page and return the array containing its ID and IDs of its children. So here’s the code:
function get_page_and_its_children_ids_by_title( $page_title ) {
$result = array();
$page = get_page_by_title( $page_title ); // find page with given title
if ( $page ) { // if that page exists
$result[] = $page->ID; // add its ID to the result
$children = get_children( array( // get its children
'post_parent' => $page->ID,
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish'
) );
$result = array_merge( $result, array_keys( $children ) ); // add children ids to the result
}
return $result;
}
Related Posts:
- Sorting list of sites from multisite network using wp_get_sites
- How to store the_title() into a variable to reutrn the value, not just echo it
- Metabox repeating fields – radio buttons not saving correctly
- How can merge two arrays values in one array and save in database
- How to update single value in multi dimensional Post Meta?
- Error in WP_update_post
- Compare two meta key values against each other inside the get_posts array?
- Looping through WP_Post Object
- Need to get specific data from array
- Using a javascript file to access a get posts array
- Create an array from an array
- WP_User_Query order by meta_key that is an array
- How do I output a database option that is an array into a get_posts array?
- Can an array be used as a meta_query value?
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- How do I dynamically generate args for wp_query?
- List of posts by day of the week
- Check if term object is in array
- Must Use Plugin Causing Query Error
- ‘orderby’ => ‘rand’ alternative for better performance?
- How to convert objects into arrays
- Parsing php string in jquery [closed]
- Admin Options page. Save as Array
- PHP get the first post separately from array returned by wpdb->get_results()
- Working with query_posts ( arrays and query strings)
- how can i show only the parents in owl-carousel?
- Create shortcodes within foreach loop (using array)
- Using a variable in is_page(array())
- Remove duplicates – array_unique()
- How can I add multiple ‘tax_query’ arrays via a loop?
- How to properly loop through these external URLs to get them into the sitemap using this hook
- Recent posts with featured image or fallback image with permalink
- Call global variable array() in woocommerce child/template
- Storing Array from returned database query and using the array in a new query
- get_the_tags() not iterating through for/while loop, but will with foreach
- get a simple array of all of the term names that exist in all taxonomies
- Populate dropdown with Child Pages based on Parent Page chosen
- How to use $query->set with post__in?
- Reprinting tags with all attributes
- PHP Array Returning [object Object]. Tried existing answers results with no luck
- foreach loop still echoes array
- Exclude posts based on meta value
- Checking array against author id in loop
- Alter required message using comment form api
- Advanced Custom Fields – display label and value only if value entered
- meaning of (array)function()
- Grouping posts by a custom meta value
- wp_force_remove_style’ not found
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- How can I access string value in an array?
- How to use if statement in an array? [closed]
- How to array only one key from another array
- Filtering a function’ output for a new continued function
- Get html data with javascript to php array and store to wordpress database
- How do I create a numbered list with PHP? [closed]
- Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
- How to use array in function to get only value I want
- Error while setting role
- Get categories names as an array to use it in theme settings
- How to get the last category name of a child category?
- How to say if meta_value is greater than 0 in an array?
- How to use two meta_compare in an array?
- Warning: in_array() null given in PHP function
- Foreach loop inside an array_merge
- Loop over Array and get the distinct ids
- How to access or parse key/values that have “string”
- If Array Values Match Another Array’s Values, Then
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Only show first image in foreach loop
- Conditional multidimensional arrays and array_map
- How can I get all values from my array in a loop in php? [closed]
- Getting posts to exclude from array
- Get all posts as an array ID => Name
- I’m unable to call img path using single quotes in an array?
- Filter by field with array value in ACF on WP REST API
- What is this mark for “? function()” [closed]
- How to combine array info [closed]
- Populate checkboxes from array
- Use php array outside his function
- PHP Use Declared array Variable inside already Declared Array
- Retrieve Array from within Array [closed]
- Force array to be a string [closed]
- Why is my array_diff usage breaking things?
- get_body_params() is always empty in POST request
- Grabbing value of input field inside of array
- save array of objects with update_option
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- How to group by column a and sum column b and c in a php array
- Replace block content with an array
- Adding date and time to the same request
- PHP how to submit array elements to database
- PHP – Converting elements to actual values
- Send emails to individual subscribers when CPT post is deleted (trashed)
- How to pass php array to external js file in WordPress
- Get check box values inside array for use in posting form data
- Warning: Array to string conversion in /css/base.php on line 500 [closed]
- Updating from multiple array custom table
- Inserting more than one array into same row