• 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:

    <?php
    $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. ]

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think you’ll need to craft a query like this:
    query_posts('meta_key=category&meta_value=3');

    Thread Starter anotherbreed

    (@anotherbreed)

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show posts in a page from the Category number written in a Custom Field’ is closed to new replies.