WordPress.org

Ready to get started?Download WordPress

Forums

Drop site for sorting custom fields (2 posts)

  1. etoed
    Member
    Posted 1 year ago #

    On the site a large number of samples of materials.
    Each sample = 1 post.
    Each pattern has a few additional fields (such as color, collection).

    Needs sorting, which will display all the samples at once, the fields that meet "green or red, or blue," where it naturally is in the form of checkboxes.
    So is the variant display only "red".

    Here is my code:
    In the template, call the function over form.
    It works, but if you choose colors like 7.5 (and materials in the database> 500) the site falls.

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    function cat_sort () {
    global $ wp_query;
    $ cat_ID = get_query_var ('cat');
    $ param = $ _POST; / / get the post
    $ i = 1;
    foreach ($ param as $ key => $ value) {
    $ type = $ key;
    if ($ i) {
    $ mass = count ($ value);
    if ($ mass> 1) {
    $ ar = array ('relation' => 'OR'); / / parent array. later will vary, depending on the input parameters.
    }
    }
    unset ($ i);
    foreach ($ value as $ val) {
    $ ar [] = array (
    'key' => $ type,
    'value' => $ val,
    'compare' => 'IN' / / later will vary, depending on the input parameters
    );
    }
    }
    $ args1 = array (
    'post_type' => 'post',
    'cat' => $ cat_ID,
    
    'meta_query' => $ ar
    ) ;/ / Total
    if ($ _POST) {
    $ q = new WP_Query ($ args1);
    
    } else {
    $ q = new WP_Query ("cat = $ cat_ID");
    }
    return $ q;
    }

    I apologize for the broken English, used Google translator).

    How to properly take account of the current category, which in random fields is "red" or "green" or "blue" ...
    If the basis of more than 500 entries, 700.

  2. etoed
    Member
    Posted 1 year ago #

    the choice to display more than 6 colors - site falls
    an error 503

Topic Closed

This topic has been closed to new replies.

About this Topic