Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress: Dynamically pass meta_key variables into query_posts

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #35917
    friiitz
    Member

    Hi guys, this is what I want to achieve – but I have no clue how to manage to do this dynamically.

    1. get the meta values of all keys of a specific metabox where the meta value is = 1
    or get all the meta values of meta keys that start with “prodcat_” where the meta value is = 1 (I have no idea which is easier/works at all)
    2. pass the associated meta keys into individual variables (e.g. $prodcat)
    3. which can then be used to feed a custom query to define the posts listed on a page (see below)

    // The Query
    $args = array(
    'post_type'=> 'page',
    'post_status'=> 'publish',
    'meta_query' => array(
    //'relation' => 'OR',
    array(
    'key' => $prodcat1,
    'value' => 1
    ),
    array(
    'key' => $prodcat2,
    'value' => 1
    ),
    array(
    'key' => $prodcat3,
    'value' => 1
    ),
    // and so on, depending on the number of results
    ),
    'orderby'=> 'title',
    'order' => 'ASC'
    );
    query_posts( $args );

    Does anyone know how to get this done?

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.