WordPress.org

Ready to get started?Download WordPress

Forums

Excluding from the Loop posts having a certain Custom Field (2 posts)

  1. Claudio Simeone
    Member
    Posted 8 years ago #

    Hi all,
    this is my problem: I add a Custom Field to some posts to show them in a flash ticker in the blog header.
    The Key is 'ticker' and its value is '1'.

    Now, I want to exclude these posts from the Loop in the home, and show only posts that don't have that custom field (ticker).

    I tried also with a custom query like:

    $arts = $wpdb->get_results("SELECT P2C.*, POST.ID, POST.post_title, POST.post_date
    FROM $wpdb->posts POST, $wpdb->postmeta P2C
    WHERE POST.ID = P2C.post_id AND P2C.meta_key != 'ticker' AND POST.post_status = 'publish'
    ORDER BY POST.post_date DESC");

    but the problem is that if a Post has another custom field, the query doesn't work, probably because there's more than a record in the wp_postmeta table.

    I could use this
    $arts = $wpdb->get_results("SELECT ID,post_title,post_date FROM $wpdb->posts WHERE post_status = 'publish' AND ID NOT IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'ticker') ORDER BY post_date DESC");
    but unfortunately doesn't work with mySQL version available on my hosting service.

    I read also the Query Posts on the Wiki, but it seems applicable only to categories.

    Any ideas?
    Thanks in advance.

  2. lellie
    Member
    Posted 8 years ago #

    Did you manage to get this working?

Topic Closed

This topic has been closed to new replies.

About this Topic