Plugin Directory

Changeset 2756655


Ignore:
Timestamp:
07/15/2022 01:43:36 AM (4 years ago)
Author:
madebycinza
Message:

cinza grid v1.0.3

Location:
cinza-grid
Files:
22 added
6 edited

Legend:

Unmodified
Added
Removed
  • cinza-grid/trunk/assets/css/backend-style.css

    r2756131 r2756655  
    2525
    2626#cgrid-optionset .cgrid-options input[type="text"],
     27#cgrid-optionset .cgrid-options input[type="number"],
    2728#cgrid-optionset .cgrid-options select {
    2829    width: 150px;
     30}
     31
     32#cgrid-optionset .cgrid-options input[type="text"]#cgrid_tax_terms {
     33    width: 100% !important;
    2934}
    3035
     
    4045#cgrid-options textarea {
    4146    height: 150px;
     47}
     48
     49#cgrid-optionset .meta-disabled {
     50    display: none;
    4251}
    4352
  • cinza-grid/trunk/cinza-grid.php

    r2756582 r2756655  
    55 * Plugin URI:        https://cinza.io/plugin/grid
    66 * Description:       A minimal grid plugin.
    7  * Version:           1.0.2
     7 * Version:           1.0.3
    88 * Requires at least: 5.2
    99 * Requires PHP:      7.2
  • cinza-grid/trunk/includes/backend-cpts.php

    r2756582 r2756655  
    154154    $temp_posttype = 'post';
    155155    $temp_orderby = 'date';
     156    $temp_orderby_meta = '';
    156157    $temp_order = 'ASC';
     158    $temp_num = '-1';
     159    $temp_tax = '';
     160    $temp_tax_terms = '';
    157161    $temp_sorting = '';
    158162    $temp_filters = '';
     
    187191        $temp_posttype = esc_attr($cgrid_options['cgrid_posttype']);
    188192        $temp_orderby = esc_attr($cgrid_options['cgrid_orderby']);
     193        $temp_orderby_meta = esc_attr($cgrid_options['cgrid_orderby_meta']);
    189194        $temp_order = esc_attr($cgrid_options['cgrid_order']);
     195        $temp_num = esc_attr($cgrid_options['cgrid_num']);
     196        $temp_tax = esc_attr($cgrid_options['cgrid_tax']);
     197        $temp_tax_terms = esc_attr($cgrid_options['cgrid_tax_terms']);
    190198        $temp_sorting = esc_attr($cgrid_options['cgrid_sorting']);
    191199        $temp_filters = esc_attr($cgrid_options['cgrid_filters']);
     
    261269            <tr>
    262270                <td class="cgrid-options col-1">
     271                    <label for="cgrid_order">Number of items</label>
     272                </td>
     273                <td class="cgrid-options col-2">
     274                    <input type="number" name="cgrid_num" id="cgrid_num" value="<?php echo esc_attr($temp_num); ?>" />
     275                </td>
     276            </tr>
     277            <tr>
     278                <td class="cgrid-options col-1">
    263279                    <label for="cgrid_orderby">Order by</label>
    264280                </td>
    265281                <td class="cgrid-options col-2">
    266                     <select name="cgrid_orderby" id="cgrid_orderby">
     282                    <select name="cgrid_orderby" id="cgrid_orderby" onchange="sortByMetaField(this)">
    267283                        <option value="date" <?php if(isset($temp_orderby) && ($temp_orderby == 'date'))  echo 'selected="selected"'; ?>>Date</option>
    268284                        <option value="id" <?php if(isset($temp_orderby) && ($temp_orderby == 'id'))  echo 'selected="selected"'; ?>>ID</option>
     
    270286                        <option value="modified" <?php if(isset($temp_orderby) && ($temp_orderby == 'modified'))  echo 'selected="selected"'; ?>>Modified</option>
    271287                        <option value="title" <?php if(isset($temp_orderby) && ($temp_orderby == 'title'))  echo 'selected="selected"'; ?>>Title</option>
     288                        <option value="meta_value" <?php if(isset($temp_orderby) && ($temp_orderby == 'meta_value'))  echo 'selected="selected"'; ?>>Meta Field</option>
    272289                    </select>
     290                    <input type="text" name="cgrid_orderby_meta" id="cgrid_orderby_meta" placeholder="field_name" value="<?php echo esc_attr($temp_orderby_meta); ?>" class="meta-disabled" disabled />
    273291                </td>
    274292            </tr>
     
    282300                        <option value="DESC" <?php if(isset($temp_order) && ($temp_order == 'DESC'))  echo 'selected="selected"'; ?>>DESC</option>
    283301                    </select>
     302                </td>
     303            </tr>
     304            <tr>
     305                <td class="cgrid-options col-1">
     306                    <label for="cgrid_order">Taxonomy</label>
     307                </td>
     308                <td class="cgrid-options col-2">
     309                    <input type="text" name="cgrid_tax" id="cgrid_tax" placeholder="taxonomy_name" value="<?php echo esc_attr($temp_tax); ?>" />
     310                </td>
     311            </tr>
     312            <tr>
     313                <td class="cgrid-options col-1">
     314                    <label for="cgrid_order">Taxonomy terms</label>
     315                </td>
     316                <td class="cgrid-options col-2">
     317                    <input type="text" name="cgrid_tax_terms" id="cgrid_tax_terms" placeholder="term_slug1, term_slug2, term_slug3" value="<?php echo esc_attr($temp_tax_terms); ?>" />
    284318                </td>
    285319            </tr>
     
    383417                    <textarea type="text" class="widefat cgrid-content" name="cgrid_filters"><?php echo esc_html($temp_filters); ?></textarea>
    384418                    <p><strong>Notes:</strong></p>
    385                     <p>Filters only work with <code>%meta('x')%</code> and <code>%tax('x')%</code>.</p>
     419                    <p>Filters only work with <code>%meta('field_name')%</code> and <code>%tax('taxonomy_name')%</code>.</p>
    386420                    <p>To filter by the 'color' meta field, with the default button called "All Colors" and filters for the colors Blue, Red and Yellow, you should enter the following in the Filter textarea:</p>
    387421                    <p><code>%meta('color')% / Colors / Blue, Red, Yellow</code></p>
     
    390424        </tbody>
    391425    </table>
     426   
     427    <script>
     428        sortByMetaField();
     429        function sortByMetaField(sender) {
     430            let val = document.getElementById("cgrid_orderby").value;
     431            if (val == "meta_value") {
     432                jQuery("#cgrid_orderby_meta").removeClass("meta-disabled");
     433                jQuery("#cgrid_orderby_meta").prop( "disabled", false );
     434            } else {
     435                jQuery("#cgrid_orderby_meta").addClass("meta-disabled");
     436                jQuery("#cgrid_orderby_meta").prop( "disabled", true );
     437            }
     438        }
     439    </script>
    392440    <?php
    393441}
     
    511559    $cgrid_posttype = sanitize_text_field($_POST['cgrid_posttype']);
    512560    $cgrid_orderby = sanitize_text_field($_POST['cgrid_orderby']);
     561    $cgrid_orderby_meta = wp_filter_post_kses($_POST['cgrid_orderby_meta']);
    513562    $cgrid_order = sanitize_text_field($_POST['cgrid_order']);
     563    $cgrid_num = wp_filter_post_kses($_POST['cgrid_num']);
     564    $cgrid_tax = wp_filter_post_kses($_POST['cgrid_tax']);
     565    $cgrid_tax_terms = wp_filter_post_kses($_POST['cgrid_tax_terms']);
    514566    $cgrid_sorting = wp_filter_post_kses($_POST['cgrid_sorting']);
    515567    $cgrid_filters = wp_filter_post_kses($_POST['cgrid_filters']);
     
    542594    $new['cgrid_posttype'] = empty($cgrid_posttype) ? 'post' : wp_strip_all_tags($cgrid_posttype);
    543595    $new['cgrid_orderby'] = empty($cgrid_orderby) ? 'date' : wp_strip_all_tags($cgrid_orderby);
     596    $new['cgrid_orderby_meta'] = empty($cgrid_orderby_meta) ? '' : wp_strip_all_tags($cgrid_orderby_meta);
    544597    $new['cgrid_order'] = empty($cgrid_order) ? 'ASC' : wp_strip_all_tags($cgrid_order);
     598    $new['cgrid_num'] = empty($cgrid_num) ? '-1' : wp_strip_all_tags($cgrid_num);
     599    $new['cgrid_tax'] = empty($cgrid_tax) ? '' : wp_strip_all_tags($cgrid_tax);
     600    $new['cgrid_tax_terms'] = empty($cgrid_tax_terms) ? '' : wp_strip_all_tags($cgrid_tax_terms);
    545601    $new['cgrid_sorting'] = empty($cgrid_sorting) ? '' : wp_filter_post_kses($cgrid_sorting);
    546602    $new['cgrid_filters'] = empty($cgrid_filters) ? '' : wp_filter_post_kses($cgrid_filters);
  • cinza-grid/trunk/includes/backend-shortcodes.php

    r2756582 r2756655  
    4040    // Retrieves an array of the latest posts, or posts matching the given criteria
    4141    // https://developer.wordpress.org/reference/functions/get_posts/
    42     $args = array(
    43         'post_type' => esc_attr($cgrid_options['cgrid_posttype']),
    44         'post_status' => 'publish',
    45         'numberposts' => -1,
    46         'orderby' => esc_attr($cgrid_options['cgrid_orderby']),
    47         'order' => esc_attr($cgrid_options['cgrid_order']),
    48     );
     42    $aux_orderby_meta = esc_attr($cgrid_options['cgrid_orderby']) === "meta_value";
     43    $aux_taxonomy = !empty(esc_attr($cgrid_options['cgrid_tax'])) && !empty(esc_attr($cgrid_options['cgrid_tax_terms']));
     44    $aux_taxonomy_terms = explode (",", esc_attr($cgrid_options['cgrid_tax_terms']));
     45   
     46    if ($aux_orderby_meta && $aux_taxonomy) {
     47        echo('Scenario 1');
     48        $args = array(
     49            'post_type' => esc_attr($cgrid_options['cgrid_posttype']),
     50            'post_status' => 'publish',
     51            'numberposts' => esc_attr($cgrid_options['cgrid_num']),
     52            'meta_key' => esc_attr($cgrid_options['cgrid_orderby_meta']),
     53            'orderby' => 'meta_value',
     54            'order' => esc_attr($cgrid_options['cgrid_order']),
     55            'tax_query' => array(
     56                array(
     57                    'taxonomy' => esc_attr($cgrid_options['cgrid_tax']),
     58                    'field'    => 'slug',
     59                    'terms'    => $aux_taxonomy_terms,
     60                ),
     61            ),
     62        );
     63    } else if (!$aux_orderby_meta && $aux_taxonomy) {
     64        echo('Scenario 2');
     65        $args = array(
     66            'post_type' => esc_attr($cgrid_options['cgrid_posttype']),
     67            'post_status' => 'publish',
     68            'numberposts' => esc_attr($cgrid_options['cgrid_num']),
     69            'orderby' => esc_attr($cgrid_options['cgrid_orderby']),
     70            'order' => esc_attr($cgrid_options['cgrid_order']),
     71            'tax_query' => array(
     72                array(
     73                    'taxonomy' => esc_attr($cgrid_options['cgrid_tax']),
     74                    'field'    => 'slug',
     75                    'terms'    => $aux_taxonomy_terms,
     76                ),
     77            ),
     78        );
     79    } else if ($aux_orderby_meta && !$aux_taxonomy) {
     80        echo('Scenario 3');
     81        $args = array(
     82            'post_type' => esc_attr($cgrid_options['cgrid_posttype']),
     83            'post_status' => 'publish',
     84            'numberposts' => esc_attr($cgrid_options['cgrid_num']),
     85            'meta_key' => esc_attr($cgrid_options['cgrid_orderby_meta']),
     86            'orderby' => 'meta_value',
     87            'order' => esc_attr($cgrid_options['cgrid_order']),
     88        );
     89    } else {
     90        echo('Scenario 4');
     91        $args = array(
     92            'post_type' => esc_attr($cgrid_options['cgrid_posttype']),
     93            'post_status' => 'publish',
     94            'numberposts' => esc_attr($cgrid_options['cgrid_num']),
     95            'orderby' => esc_attr($cgrid_options['cgrid_orderby']),
     96            'order' => esc_attr($cgrid_options['cgrid_order']),
     97        );
     98    }
    4999    $posts = get_posts( $args );
    50100   
  • cinza-grid/trunk/readme.txt

    r2756582 r2756655  
    55Tested up to: 6.0
    66Requires PHP: 7.2
    7 Stable tag: 1.0.2
     7Stable tag: 1.0.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2222
    2323== Changelog ==
     24= 1.0.3 =
     25*Release Date - 14th July, 2022*
     26
     27* Added new parameters for WP Query: number of items, order by meta field, taxonomy and taxonomy terms
     28
    2429= 1.0.2 =
    2530*Release Date - 14th July, 2022*
Note: See TracChangeset for help on using the changeset viewer.