ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Limiting exp:query search to just status="open"

January 06, 2011 8:24am

Subscribe [4]
  • #1 / Jan 06, 2011 8:24am

    Etheya

    213 posts

    I have the following code on a clients site which is showing the amount of images within a given category along with a category image… which is working great..

    ({exp:query sql="SELECT count(exp_category_posts.entry_id )  AS post_count FROM exp_category_posts WHERE exp_category_posts.cat_id = {category_id}"}{post_count}{/exp:query} images in this category)

    But im trying to limit this count to only the entries that have status=“open” to which i think i have the right code.. but just cant seem to put it in the right place to get it to work… any ideas anyone?

    exp_weblog_titles.status='open'
  • #2 / Jan 06, 2011 8:35am

    Focus Lab Dev Team

    1129 posts

    Hey Brian,

    You need to use a sql join to check for the entry status. Here’s the query:

    SELECT
        count(exp_category_posts.entry_id) AS post_count
    FROM
        exp_category_posts
    NATURAL JOIN
        exp_weblog_titles
    WHERE
        exp_category_posts.cat_id = {category_id}
        AND
        exp_weblog_titles.status = 'open'
  • #3 / Jan 06, 2011 8:37am

    Etheya

    213 posts

    Hi Erik,

    Sure ive tried that, but will give it a go… probably missing a ’ or something knowing my luck.

  • #4 / Jan 06, 2011 8:41am

    Etheya

    213 posts

    Hmmm that just returned 0 images now…

    see http://www.mikemcfarlane.co.uk/gallery/

    ({exp:query sql="SELECT
                    count(exp_category_posts.entry_id) AS post_count
                    FROM
                        exp_category_posts
                    NATURAL JOIN
                        exp_weblog_titles
                    WHERE
                        exp_category_posts.cat_id = {category_id}
                        AND
                        exp_weblog_titles.status = 'open'  = {category_id}"}{post_count}{/exp:query} images in this category)
  • #5 / Jan 06, 2011 8:43am

    Net Resources

    26 posts

    Without joins, but how about:

    SELECT
        count(exp_category_posts.entry_id) AS post_count
    FROM
        exp_category_posts, exp_channel_titles
    WHERE
        exp_category_posts.cat_id = {category_id}
        AND
        exp_category_posts.entry_id = exp_channel_titles.entry_id
        AND
        status = 'open'
  • #6 / Jan 06, 2011 8:45am

    Focus Lab Dev Team

    1129 posts

    Hmmm that just returned 0 images now…

    see http://www.mikemcfarlane.co.uk/gallery/

    The link looks like it’s showing image counts to me. Am I looking in the wrong place? (I don’t see any 0’s)

  • #7 / Jan 06, 2011 8:55am

    Etheya

    213 posts

    Tis fixed… thanks Erik

  • #8 / Jan 06, 2011 4:02pm

    Ingmar

    29245 posts

    Thanks for the assist, Erik. Glad to see you’re all set, please post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases