Show posts in a page from the Category number written in a Custom Field (3 posts)

  1. anotherbreed
    Posted 3 years ago #

    Hi there,

    I'm trying to find out a way to show in a page some posts from a category number that I will later specify in a Custom Field called "category".

    I have this working code to modify:

    $my_query = new WP_Query('cat=3&posts_per_page=24&orderby=rand');
    while ($my_query->have_posts()) : $my_query->the_post();

    I need to replace "cat=3" with something that tells WordPress to take the category number I will write into the Custom Field instead of that number 3.

    I think I need something like this:

    <?php get_post_custom_values($category, $post_id); ?>

    But I am not so expert with PHP to correctly integrate this code in the example above - in fact I always encountered errors.

    Any ideas appreciated!
    Many thanks

    [ Please do not bump, that's not permitted here. ]

  2. Corey Salzano
    Posted 3 years ago #

    I think you'll need to craft a query like this:

  3. anotherbreed
    Posted 3 years ago #

    Hi Corey,

    thank you for your reply, I finally found some time to get back working on this.

    About your code, I think that's not exactly what I'm looking for. I need to replace the number 3 with a dynamic number. The code should be like "cat= take the current value stored in the custom field named category".

    So that if I write 5 in the custom field of the current page, it will dinamically become "cat=5" in the code.

    I hope everything is clear now.

Topic Closed

This topic has been closed to new replies.

About this Topic