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.
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.
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
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
);Thanks a lot MichaelH ;-)
Could use the 'post_parent' => $post[0]->ID, argument
When i use this argument, it doesn't display anything, am I missing something?
What if I wanted to display only urls or other cutom fields from the parent page of the current page?
Any suggestion regarding my last question?
This topic has been closed to new replies.