0

First of all sorry for my earlier post, it was just too confusing, and I asked 3 questions in 1...

Okay the code below gets be all the pages with the page type

page_library_html_content.php

now I would like to add to this code and have it show all the pages with page type

page_library_css_content.php

too. So I will get all the pages with these two page types.

Code

<?php
$product_pages_args = array(
    'meta_key' => '_wp_page_template',
    'meta_value' => 'page_library_html_content.php',
    'hierarchical' => '0',
);
$product_pages = get_pages( $product_pages_args );
?>

<?php
foreach ( $product_pages as $product_page ) {
    $author_id =  get_post_field('post_author', $product_page->ID );
    $author_details = get_user_by( 'id', $author_id );
    $author_name = $author_details->first_name . ' ' . $author_details->last_name;  

    echo '<div id="posts" class="flex_100"><div class="posts_bar"></div>';
    echo '<div id="library_title"><a href="' . get_permalink( $product_page->ID ) . '">' . $product_page->post_title  . '</a></div>';
    echo '<div class="library-content">' . get_post_field('post_content', $product_page->ID ) . '</div>';
     echo '<div class="library-author">Tutorial Instructor:  ' . $author_name . '</div>';
    echo '<div class="library-author-av">' . get_avatar( $author_id , 32 ) . '</div></div>';;

}
?>
0

You should use 'meta_query' instead it is a array of arrays

$product_pages_args = array(
    'meta_query' => array(
      array(
       'key' => '_wp_page_template',
       'value' => array('page_library_html_content.php',page_library_css_content.php') ,
       'compare' => 'IN'
    ), 
    )
)
  • Okay so my code now is link but it just seems to show every page? - Thanks – aled2305 Dec 29 '13 at 5:16
  • I forgot to add the 'compare', i updated the code, try it now. – Robin Westerlundh Dec 29 '13 at 17:07
  • Okay so is the code correct here because it still shows all of the posts - Thanks – aled2305 Dec 29 '13 at 18:40
  • Can anyone help me? Please – aled2305 Jan 2 '14 at 10:17
  • I updated the answer to reflect the fact that the meta values only use one key. And created an array of values. I do not have a wp install to test but meta query is the right way to go. – Robin Westerlundh Jan 3 '14 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.