I have a custom post page set below:

function keyword_tiles_init() {
    $args = array(
      'label' => 'Keywords',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'page',
        'hierarchical' => true,
        'rewrite' => array('slug' => 'keywords'),
        'query_var' => true,
        'menu_icon' => 'dashicons-admin-page',
        'supports' => array(
            // 'trackbacks',
    register_post_type( 'keyword-tile', $args );
add_action( 'init', 'keyword_tiles_init' );

It has parent and child pages. And I want to query the parent pages only:

$page_slug = 'keywords';
$slug_type = 'keyword-tile';
$output_type = ARRAY_A;
$page = get_page_by_path($page_slug, $output_type, $slug_type);



I have set the slug:

'rewrite' => array('slug' => 'keywords'),

So the param to pass in get_page_by_path should be:

$page_slug = 'keywords';

But it does not work.

Any ideas?

Read more here: Custom post type pages – get the parent pages only?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: