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

  • Resolved 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:

            'post_type' => 'attachment',
            'post_mime_type' =>'image',
            'post_status' => 'inherit',
            'posts_per_page' => -1,
            'tax_query' => 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:


    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



    The result of your tax_query:


    will be something like this one:

        0 => "attachment_category",
        1 => "gallery",
        2 => "slug",

    You need to try this query:


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

    Regards, nK.

    Thread Starter ben393


    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.