• Resolved Duncan

    (@jamodu)


    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
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Try:

    $this_page_title = the_title();
    args=array(
      'post_type' => 'page',
      'meta_key' => 'Project Group',
      'meta_value' => $this_page_title
    );

    Thread Starter Duncan

    (@jamodu)

    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
    );
    Thread Starter Duncan

    (@jamodu)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘include pages when meta_value = page title?’ is closed to new replies.