WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Latest posts from category defined by custom field, add another fixed category?

[Resolved] Latest posts from category defined by custom field, add another fixed category?

  • I have a page template with a query that shows the latest posts with a category ID which is defined by a custom field. All working fine, but I want to add another fixed category ID. My current code:

    <?php $my_query = new WP_Query(array(
      'cat'  => get_post_meta($post->ID, 'custom-field-name', true),
      'posts_per_page' => 5,
    ));?>

    So the posts from one fixed category and from one variable category defined by the custom field. How to add this category with ID #1?

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    @esmi

    Forum Moderator

    Try:

    <?php
    $my_cats = get_post_meta($post->ID, 'custom-field-name', true) . ', xx';
    $my_query = new WP_Query(array(
      'cat'  => $my_cats,
      'posts_per_page' => 5,
    ));?>

    where xx is the fixed cat id.

    Thanks! Did the job, you’re my hero 😉

    esmi

    @esmi

    Forum Moderator

    No probs. Glad I could help. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Latest posts from category defined by custom field, add another fixed category?’ is closed to new replies.