• Hello,

    I am trying to self learn the next level(for me) of PHP, s push in the right direction would greatly be appreciated…

    I am successfully using the following code to get recent posts from category “5441”

    <?php $recent = new WP_Query("cat=5441&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>

    I would like to be able to change the category number via Custom Fields.

    I have been trying to get the following to work, but do am not understanding how to apply my PHP reference materials to this.

    <?php $recent = new WP_Query("cat="get_post_meta($post->ID, "AuthorCatagoryID", true);"&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>

    Thank you in advance for any hints or answers.

Viewing 1 replies (of 1 total)
  • Hmm, assuming the $post->ID does contain the proper ID, then might try:

    $catid=get_post_meta($post->ID, "AuthorCatagoryID", true);
    $recent = new WP_Query("cat=".$catid."&showposts=5");

    or to make sure your variables are set correctly:

    echo 'Post id is ' . $post->ID;
    $catid=get_post_meta($post->ID, "AuthorCatagoryID", true);
    echo 'AuthorCatagoryID is '. $catid;
    $recent = new WP_Query("cat=".$catid."&showposts=5");

    Also AuthorCatagoryID <> AutorCategoryID

Viewing 1 replies (of 1 total)
  • The topic ‘Replacing a cat ID with a custom field in PHP’ is closed to new replies.