WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Latest posts from category defined by custom field, add another fixed category? (4 posts)

  1. Yasp0
    Member
    Posted 10 months ago #

    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?

  2. esmi
    Forum Moderator
    Posted 10 months ago #

    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.

  3. Yasp0
    Member
    Posted 10 months ago #

    Thanks! Did the job, you're my hero ;-)

  4. esmi
    Forum Moderator
    Posted 10 months ago #

    No probs. Glad I could help. :-)

Reply

You must log in to post.

About this Topic

Tags

No tags yet.