WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $post_count in custom query (2 posts)

  1. mendezki
    Member
    Posted 6 years ago #

    I'm listing posts using a custom query, inspired by this thread:

    SELECT *
    FROM $wpdb->posts
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb >term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 3
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND post_status = 'publish'
    AND post_type = 'post'
    AND post_date < NOW()
    AND post_expire_date > NOW()
    ORDER BY post_end_date DESC`

    If I'd use a custom wp query along the lines of $my_query = new WP_Query... it would be quite easy to use $post_count to make stuff happen on nth posts. However, this doesn't allow for selecting and ordering by custom fields. I'm wondering how I would implement $post_count functionality using a query like above?

    Background: What I'm trying to accomplish is to have a left floated (inline, if you will) list of (blocks of) posts. Where each post might be of varying length just floating them will not produce a proper visual result. Each new 'line' won't start from the outermost left side, but bumps into the 'longest' post it encounters on its left hand. To work around this problem I'd assign a selector to each sixth list element, clear:left-ifiying it so everything works nicely. Hence the $post_count issue...

  2. mendezki
    Member
    Posted 6 years ago #

    Oof, it was late at my side of the globe...

    Simply adding $post_count++

    <?php setup_postdata($post); $post_count++; ?>

    did the trick.

Topic Closed

This topic has been closed to new replies.

About this Topic