Hi,
I'm trying to create a 'related pages' navigation and I need to include pages that have a custom field value equal to the page title.
I've used this code, but it doesn't work properly - please can someone help?
<?php
global $post;
$args=array(
'post_type' => 'page',
'meta_key' => 'Project Group',
'meta_compare' => '=',
'meta_value' => 'the_title();'
);
$pages = get_posts($args);
if ($pages) {
$pageids = array();
foreach ($pages as $page) {
$pageids[]= $page->ID;
}
?>
<ul>
<?php wp_list_pages('include='.implode(",", $pageids)); ?>
</ul>
<?php
}
?>
Try:
$this_page_title = the_title();
args=array(
'post_type' => 'page',
'meta_key' => 'Project Group',
'meta_value' => $this_page_title
);
Thanks for the reply esmi but I'm afraid that still doesn't work :(
$this_page_title = the_title();
@args=array(
'post_type' => 'page',
'meta_key' => 'Project Group',
'meta_value' => $this_page_title
);
Finally sorted. It needed to be get_the_title rather than just the_title...
<?php
$this_page_title = get_the_title();
global $post;
$args=array(
'post_type' => 'page',
'meta_key' => 'Project Group',
'meta_compare' => '=',
'meta_value' => $this_page_title
);
$pages = get_posts($args);
if ($pages) {
$pageids = array();
foreach ($pages as $page) {
$pageids[]= $page->ID;
}
?>
<ul>
<?php wp_list_pages('include='.implode(",", $pageids)); ?>
</ul>
<?php
}
?>
Hope that helps someone else in the future.