You can get pages with get_pages()
, in the arguments you can provide a search query for post_meta
, like for example:
$args = array(
'post_type' => 'page',
'meta_key' => 'section',
'meta_query' => array( array(
'key' => 'section'
'value' => 'surgery' // here you could place get_the_title()
'compare' => '='
) )
);
$pages = get_pages( $args );
This will return all pages (or any other post types in post_type
) with meta_key section and meta_value surgery.
You have to alter the loop if you use this way, build your loop as follow:
foreach( $pages as $page ) : setup_postdata( $page );
...
endforeach; wp_reset_postdata();
Hope this will help you.