Plugin Directory

Changeset 2927964


Ignore:
Timestamp:
06/19/2023 01:16:05 PM (21 months ago)
Author:
firmcatalyst
Message:

Minor improvements, nothing overspecial

Location:
fcp-posts-by-search-query/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • fcp-posts-by-search-query/trunk/assets/advisor.js

    r2907638 r2927964  
    44    const $ = jQuery,
    55        css_prefix = 'fcp-advisor-',
    6         css_class = css_prefix+'holder',
    7         css_status_class = css_prefix+'holder-status';
    8     let init_val = '';
     6        css_class = css_prefix+'holder';
     7    let init_val = '',
     8        input_delay = setTimeout( ()=>{} );
    99
    1010    if ( !$input || !$input instanceof $ || !arr ) { return }
     
    1818    });
    1919    $input.on( 'input', function() {
    20         list_holder_fill();
     20        clearTimeout( input_delay );
     21        input_delay = setTimeout( list_holder_fill, 500 ); // ++ make abort immediately, but request delay
    2122    });
    2223    $input.on( 'keydown', function(e) {
     
    218219// ++ abort all if the field got cleared
    219220// ++? appear the loading after 0.3s
     221// ++ the option to prevent the bar from closing, just remove the <li>
  • fcp-posts-by-search-query/trunk/inc/config.php

    r2907638 r2927964  
    5858}
    5959
    60 function get_default_values() { // apply on install && only planned to be usef in fields, which must not be empty // ++ turn to the constant
     60function get_default_values() { // apply on install && only planned to be usef in fields, which must not be empty // ++ turn to the constant ++!! set up them all by the structure
    6161    return [
    6262        'main-color' => '#007cba',
  • fcp-posts-by-search-query/trunk/inc/meta-boxes.php

    r2927416 r2927964  
    6464
    6565// api to fetch the posts by search query or by id-s
     66// ++ show correct unfilled behavior!!!
    6667add_action( 'rest_api_init', function () {
    6768
     
    9697        }
    9798
    98         if ( FCPPBK_DEV ) { usleep( rand(0, 1000000) ); } // simulate server responce delay
    99 
    10099        return [
    101100            'methods'  => 'GET',
    102101            'callback' => function( \WP_REST_Request $request ) use ( $wp_query_args, $format_output ) {
     102
     103                if ( FCPPBK_DEV ) { usleep( rand(0, 1000000) ); } // simulate server responce delay
    103104
    104105                $wp_query_args['s'] = $request['search'];
  • fcp-posts-by-search-query/trunk/inc/settings-page.php

    r2907638 r2927964  
    2020            ['Additional CSS', 'textarea', [ 'filter' => 'css' ]],
    2121            ['Limit the list', 'number', [ 'placeholder' => '10', 'step' => 1, 'comment' => 'If the Layout Setting contains the List option, this number will limit the amount of posts in it', 'filter' => 'integer' ]],
     22            ['Minimum posts', 'number', [ 'placeholder' => '0', 'step' => 1, 'comment' => 'Minimum number of posts found to be printed. Doesn\'t refer to the List of particular posts', 'filter' => 'integer' ]],
    2223            ['Default thumbnail', 'image', [ 'comment' => 'This image is shown, if a post doesn\'t have the featured image', 'className' => 'image' ]],
    2324            ['Thumbnail size', 'select', [ 'options' => '%thumbnail_sizes' ]],
     
    3637            ['Select from', 'checkboxes', [ 'options' => '%get_public_post_types', 'comment' => 'Pick the post types in which the search is performed' ]],
    3738            ['Apply to', 'checkboxes', [ 'options' => '%get_public_post_types', 'comment' => 'This plugin will be applied to posts of these post types' ]],
     39            ['Unfilled behavior', 'select', [ 'options' => [ '' => 'Hide', 'search-by-title' => 'Search by Title' ] ]],
    3840        ],
    3941    ];
  • fcp-posts-by-search-query/trunk/inc/shortcode.php

    r2927416 r2927964  
    1414
    1515    $settings = get_settings();
     16    $queried_id = get_queried_object_id();
    1617
    1718    // styles
     
    4546    }
    4647
    47     // wp_reset_query(); // ++ investigate when to apply
    48 
    4948    $metas = array_map( function( $value ) { // get the meta values
    5049        return $value[0];
    51     }, array_filter( get_post_custom(), function($key) { // get only meta for the plugin
     50    }, array_filter( get_post_meta( $queried_id ), function($key) { // get only meta for the plugin
    5251        return strpos( $key, FCPPBK_PREF ) === 0;
    5352    }, ARRAY_FILTER_USE_KEY ) );
     
    5958    }, 0 );
    6059
    61     $current_id = empty( get_queried_object() ) ? 0 : get_queried_object()->ID;
    62 
    6360    $wp_query_args = [
    6461        'post_type' => get_types_to_search_among(),
    6562        'post_status' => 'publish',
    6663        'posts_per_page' => $limit,
    67         'post__not_in' => [ $current_id ], // exclude self
     64        'post__not_in' => [ $queried_id ], // exclude self
    6865        'lang' => 'all',
    6966    ];
     
    7875        break;
    7976        case ( 'query' ):
    80             $query = $metas[ FCPPBK_PREF.'query' ];
    81             if ( trim( $query ) === '' ) { return; }
     77            $query = trim( $metas[ FCPPBK_PREF.'query' ] );
     78            if ( $query === '' && $settings['unfilled-behavior'] === 'search-by-title' ) { // ++-- && is_single( $queried_id ) doesn't work somehow
     79                $query = trim( get_the_title( $queried_id ) );
     80            }
     81            if ( $query === '' ) { return; }
    8282            $wp_query_args += [ 'orderby' => 'date', 'order' => 'DESC', 's' => $query ];
    8383        break;
     
    8888    $search = new \WP_Query( $wp_query_args );
    8989
    90     if ( !$search->have_posts() ) { return; }
     90    if ( !$search->have_posts() || !( $search->found_posts >= ( $settings['minimum-posts'] ?: 0 ) ) ) { return; }
    9191
    9292    $get_template = function($name, $is_part = true) {
  • fcp-posts-by-search-query/trunk/posts-by-query.php

    r2927418 r2927964  
    33Plugin Name: FCP Posts by Search Query
    44Description: Implement a list of relevant posts to particular pages with a search query or exact list of posts. Easy pick and add.
    5 Version: 1.0.2
     5Version: 1.0.3
    66Requires at least: 5.8
    77Tested up to: 6.2
  • fcp-posts-by-search-query/trunk/readme.txt

    r2927418 r2927964  
    55Tested up to: 6.2
    66Requires PHP: 7.4
    7 Stable tag: 1.0.2
     7Stable tag: 1.0.3
    88Author: Firmcatalyst, Vadim Volkov, Aude Jamier
    99Author URI: https://firmcatalyst.com
Note: See TracChangeset for help on using the changeset viewer.