• Hello,

    I have some problems making a post filter in my sidebar..
    I would need to display all the recent posts that are from the same category as the current post, and must have the same value from a custom field as the current displayed post.

    I have tried something like that, but thn there is the category problem

    <?php $cur_post_value = get_post_meta($post->ID, 'town', true);
    
    $other_posts_with_value = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'town'
        AND wpostmeta.meta_value = '".$cur_post_value."'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        ORDER BY wposts.post_date DESC
        LIMIT 4
     ";
    $other_posts_array = $wpdb->get_results($other_posts_with_value,
     OBJECT); ?>
    
    <?php if ($other_posts_array): ?>

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • can this help?

    $category = get_the_category();
    if (!empty($category))
    $cat_tree = get_category_parents($category[0]->term_id, FALSE, ‘:’, TRUE);
    $top_cat = split(‘:’,$cat_tree);
    $cat_slug = $top_cat[0];

    query_posts(‘posts_per_page=15&category_name=’.$cat_slug.’&orderby=rand’);

    Thread Starter eian00

    (@eian00)

    and how would it show the posts with that category and with the same value from a custom field?

    now there should be a way to join mine and your code, but how?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sidebar post filter’ is closed to new replies.