Forums

Displaying Posts from a Category ID Listed in a Custom Field (8 posts)

  1. rawlimit
    Member
    Posted 1 year ago #

    I wanted to display a list of posts, on a page, from a specific category number specified in a custom field on the page.

    Any Ideas?

    Thanks
    Scott

  2. vtxyzzy
    Member
    Posted 1 year ago #

    I do exactly that in my site here, and in several other pages. The category name is in a Custom Field named 'category-to-show'. The relevant code is:

    <?php $this_cat=get_post_meta($post->ID,'category-to-show',TRUE);
    if ($this_cat != "") {
       $paged = get_query_var('paged');
       $args = array( 'category_name' => $this_cat, 'paged' => $paged,);
       query_posts($args);
  3. rawlimit
    Member
    Posted 1 year ago #

    Thanks for the response...

    Tried the code but it is giving me a syntax error. Please forgive as I am just learning php/wp...

    Could you elaborate?

    Thanks in advance!

  4. vtxyzzy
    Member
    Posted 1 year ago #

    That code is not meant to be used 'as is'. It must be adapted to your theme. Without access to the theme code, I cannot give more specific instructions.

    Can you post the code for your page template in a pastebin and post the link to it here?

  5. rawlimit
    Member
    Posted 1 year ago #

    http://wordpress.pastebin.com/3Je37jmX

    Trying to display the posts in the 'storepage' area
    store_couponcat being the custom field

    Thanks Again

  6. vtxyzzy
    Member
    Posted 1 year ago #

    Try adding the code as shown below just ahead of your if (have_posts()):

    <?php query_posts(
         array_merge($wp_query->query,
                    array('cat' => $store_couponcat))
    ); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  7. rawlimit
    Member
    Posted 1 year ago #

    Tried that code, and its not displaying anything...

    Here is my current code with the category# built in (141)

    http://wordpress.pastebin.com/BunS9RAk

    Anything else you think will work?

    Thanks for all the help!
    Scott

  8. vtxyzzy
    Member
    Posted 1 year ago #

    Well, if your code is working, and $store_couponcat really has what you think it has, then this should work:

    query_posts("cat=$store_couponcat");

    If that doesn't work, then $store_couponcat does not contain the category id that you are expecting.

Topic Closed

This topic has been closed to new replies.

About this Topic