Ready to get started?Download WordPress


List articles from a specific category (5 posts)

  1. ddjjmm
    Posted 4 years ago #

    Hi, my problem is this:

    i use custom fields of a page (portfolio_inhalte_kategorie_id) which stands for an article category id.

    Now i want to implement a feature that gives out all the articles in just this category (id).

    $portfolio = get_post_custom_values("portfolio_inhalte_kategorie_id");
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    if (get_post_custom_values("portfolio_inhalte_kategorie_id")) {
    $category = (get_post_custom_values("portfolio_inhalte_kategorie_id"));
    } else {
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

    my problem: wordpress always spit out all items of all categories and not only my chosen (id).

    I even tested the if cases with simple echo of the chosen custom field id which works. but finally the output of the articles is wrong.

    Any idea? :(

  2. keesiemeijer
    Posted 4 years ago #

    get_post_custom_values needs to be in a loop if you don't specify a post ID and returns an array so you cannot use it with 'cat='.$category

  3. ddjjmm
    Posted 4 years ago #

    how can i solve it or use another way to take custom fields for listing category's article?

  4. keesiemeijer
    Posted 4 years ago #

    if it's just one category ID you give as value in the custom field you can use this in your page template:

    $category = get_post_meta($posts[0]->ID, 'portfolio_inhalte_kategorie_id', true);
  5. ddjjmm
    Posted 4 years ago #

    That's the way i tried too.

    Just the $posts[0]->ID was missing, thanks for help at all!

Topic Closed

This topic has been closed to new replies.

About this Topic