• Hello I have a few pages which use custom fields, e.g. ’email’ and ‘url’; I was wondering how to display on a new page a list of urls retrieved from all pages which use the ‘url’ custom field.

Viewing 7 replies - 1 through 7 (of 7 total)
  • List all pages and then all posts with specific custom field

    <?php
    $type = 'page';
    $args=array(
        'post_type' => $type,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'meta_key' => 'url',
        'caller_get_posts'=> 1
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of: ' . $type .'(s)';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        endwhile;
      } //if ($my_query)
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Related:
    query_posts()
    Custom Fields
    Page Templates

    Thread Starter baga

    (@baga)

    Thanks MichaelH!

    I added the line:
    <p><?php echo get_post_meta($post->ID, 'url', true); ?></p>
    and it works perfectly.

    What should I add if I wanted to display only urls or other cutom fields from subpages of the current page?

    What should I add if I wanted to display only urls or other cutom fields from subpages of the current page?

    Could use the 'post_parent' => $post[0]->ID, argument

    $args=array(
        'post_type' => $type,
        'post_parent' => $post[0]->ID,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'meta_key' => 'url',
        'caller_get_posts'=> 1
        );

    Thread Starter baga

    (@baga)

    Thanks a lot MichaelH ??

    Thread Starter baga

    (@baga)

    Could use the ‘post_parent’ => $post[0]->ID, argument

    When i use this argument, it doesn’t display anything, am I missing something?

    Thread Starter baga

    (@baga)

    What if I wanted to display only urls or other cutom fields from the parent page of the current page?

    Thread Starter baga

    (@baga)

    Any suggestion regarding my last question?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display data from custom fields’ is closed to new replies.