[resolved] WP_Query inside functions.php (4 posts)

  1. billygates
    Posted 5 years ago #


    there is a custom WP theme. The directory with the theme also contains function.php file where are stored frequently used theme shortcuts. index.php of this theme shows the recent posts via the global loop. Also I want to show on index.php links to some static pages which meet some condition.

    To do that I create a function in functions.php like this:

    function print_custom_pages($tp)
      $query = new WP_Query("post_type=page&meta_key=pg_type&meta_value=$tp");
      while ($query->have_posts()) {
         /* echo "POST found<br />\n"; */  // is not printed
         the_permalink(); // print a permalink of the page

    but it does not work: no posts are found via WP_Query. What I am doing wrong?


  2. esmi
    Forum Moderator
    Posted 5 years ago #


    $query = new WP_Query('post_type=page&meta_key=pg_type&meta_value=' . $tp');

  3. billygates
    Posted 5 years ago #

    @esmi: does not work, as far as understand there is no difference, just an alternative way to write the same thing.

  4. billygates
    Posted 5 years ago #

    question is closed. the problem was in 'Exclude Pages' plugin. Thanks to all for your time.

Topic Closed

This topic has been closed to new replies.

About this Topic