Support » Plugin: Visual Portfolio, Posts & Image Gallery » Problem with custom post query

  • Resolved ben393

    (@ben393)


    My Goal:

    I want the plugin to query all images in my media library with the custom taxonomy, attachment_category, equal to the slug gallery. (I have already set this up in my theme’s functions.php.)

    What I have Done:

    I built a WordPress page that correctly queries the images I want. The query uses the following array:

    array(
            'post_type' => 'attachment',
            'post_mime_type' =>'image',
            'post_status' => 'inherit',
            'posts_per_page' => -1,
            'tax_query' => array(
                array(
                    'taxonomy' => 'attachment_category',
                    'terms' => 'gallery',
                    'field' => 'slug',
                )
            )
        )

    I also use http_build_query(); to echo convert this multilevel array to a query string. I use this string to query the posts I want the plugin to display. This is the query string:

    post_type=attachment&post_mime_type=image&post_status=inherit&posts_per_page=-1&tax_query[0]taxonomy=attachment_category&tax_query[1]terms=gallery&tax_query[2]field=slug

    What Happens:

    The plugin simply displays all the images in my media library, not the images with my custom taxonomy, only.

    Any ideas on how to get the plugin to display only the images with the custom taxonomy?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author nK

    (@nko)

    Hi.

    The result of your tax_query:

    tax_query[0]taxonomy=attachment_category&tax_query[1]terms=gallery&tax_query[2]field=slug

    will be something like this one:

    array(
        0 => "attachment_category",
        1 => "gallery",
        2 => "slug",
    )
    

    You need to try this query:

    tax_query[taxonomy]=attachment_category&tax_query[terms]=gallery&tax_query[field]=slug

    p.s. I’m not sure it should work with Custom Query, didn’t tested it.

    Regards, nK.

    Thanks nK, works perfectly!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with custom post query’ is closed to new replies.