Wasteland
Wasteland

Reputation: 5379

wp - all the pages by title - not just the first one

How can I get all pages that meet the criteria?

get_page_by_title()

The above only brings the first one. Is it possible for get_page_by_title to return an array of pages?

Upvotes: 0

Views: 50

Answers (1)

Zubair Arif
Zubair Arif

Reputation: 90

Here is the code to loop all pages with title:

<?php
 $args = array(
    'sort_order' => 'asc',
    'sort_column' => 'post_title',
    'hierarchical' => 1,
    'exclude' => '',
    'include' => '',
    'meta_key' => '',
    'meta_value' => '',
    'authors' => '',
    'child_of' => 0,
    'parent' => -1,
    'exclude_tree' => '',
    'number' => '',
    'offset' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
); 
$pages = get_pages( $args); 
    foreach ($pages as $page_data) {
         $title = $page_data->post_title; 
         echo $title; 
    }
?>

You can change args to filter pages.

Upvotes: 1

Related Questions