Viewing 9 posts - 1 through 9 (of 9 total)

Custom Advanced Query

Trying to make an advanced taxonomy query like this: array( 'post_type' => 'coupon_type', 'tax_query' => array( array( 'order' => 'DESC', 'posts_per_page' => '10', 'taxonomy' => 'coupons', 'field' => 'slug', 'terms' => 'expired', // exclude expired. 'operator' => 'NOT IN') ),) Though it appears this is not possible via the Recent Listings Layout object. Is there any way to create such a query without hacking the core?

Created: August 6, 2013 at 4:41 am

  • Mark Fail
    Mark Fail
    August 6, 2013 at 5:48 am

    will it not work via a string?

  • Aaron
    August 6, 2013 at 11:03 am

    That was the first thing I tried though specific taxonomy terms don’t appear to be passed within the query string format.

    I’ll keep playing.

  • Aaron
    August 6, 2013 at 10:08 pm

    Cant get it to work at all. Looking at the php files, it appears the query already passes the post type and sets “field=slug” before the user inputted string

    So something like this does not work:

    posts_per_page=15&order=DESC&taxonomy=coupons&terms=expired&field=slug&operator=NOT IN

    It makes it difficult to query custom post types and taxonomies.

  • Aaron
    August 7, 2013 at 9:08 am

    Talking to myself mode:
    Had a brain freeze and just remembered that string will never work due to the fact you need to capture the current term as a variable before even making a query – which also requires querying two separate taxonomies.

  • Richard Bonk
    Richard Bonk
    August 7, 2013 at 9:16 am

    It all depends ‘where’ are you querying it. If you explain in more detail on what are you trying to achieve, we might be able to help you better.

    Kind regards,

    Wide range of PremiumPress and WordPress Plugins and add-ons
    PremiumPress customisation services and Website Design
    Selection of PremiumPress Child Themes

  • Aaron
    August 7, 2013 at 10:04 am

    In the Stores page, Expired Coupons are displayed. In order to get around this you can exclude a specific taxonomy term when creating a custom query, previously you could just enter cat=-232 where 232 is the category you want to exclude.

    Unfortunately terms do not work the same way and don’t appear to be able to be passed as a query string. It works fine as an array however.

  • Richard Bonk
    Richard Bonk
    August 7, 2013 at 10:33 am

    Have you tried tax_query? You can find more in here:

  • Aaron
    August 7, 2013 at 11:56 am

    Thanks Richard, it works as an array as per my first post but cannot be passed as a string. I can do it by editing core files though so this will have to suffice.

    This bit on the codex:

    tax_query takes an array of tax query arguments arrays (it takes an array of arrays) pretty much sums up the dilemma.

    Interesting that WordPress recommends against using Query Strings due to the need to parse that query before it can be used.

Copyright © 2010-2020 PremiumPress Limited.

secure payments