Plugin Directory

Changeset 2944709


Ignore:
Timestamp:
07/28/2023 03:45:01 PM (20 months ago)
Author:
firmcatalyst
Message:

Shortcode critical fix

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

Legend:

Unmodified
Added
Removed
  • fcp-posts-by-search-query/trunk/inc/shortcode.php

    r2934823 r2944709  
    99
    1010    if ( is_admin() ) { return; }
     11    if ( empty( get_types_to_search_among() ) ) { return; }
    1112
    12     if ( empty( get_types_to_search_among() ) ) { return; }
    13     if ( !in_array( get_post_type(), get_types_to_apply_to() ) ) { return; }
     13    $queried_id = get_queried_object_id();
     14    $post_type = get_post_type( $queried_id );
     15
     16    if ( !in_array( $post_type, get_types_to_apply_to() ) ) { return; }
     17
     18    if( !is_singular($post_type) ) { return; }
    1419
    1520    $settings = get_settings();
    16     $queried_id = get_queried_object_id();
    1721
    1822    // styles
     
    6771
    6872    $search_by = $metas[ FCPPBK_PREF.'variants' ] ?? 'list';
     73    $unfilled = false;
    6974
    7075    switch ( $search_by ) {
    7176        case ( 'list' ):
    7277            $ids = unserialize( $metas[ FCPPBK_PREF.'posts' ] );
    73             if ( empty( $ids ) ) { return; }
     78            if ( empty( $ids ) ) { $unfilled = true; break; }
    7479            $wp_query_args += [ 'post__in' => $ids, 'orderby' => 'post__in' ];
    7580        break;
    7681        case ( 'query' ):
    7782            $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; }
     83            if ( $query === '' ) { $unfilled = true; break; }
    8284            $wp_query_args += [ 'orderby' => 'date', 'order' => 'DESC', 's' => $query ];
    8385        break;
    8486        default:
    85             return;
     87            $unfilled = true;
    8688    }
     89   
     90    if ( $unfilled && $settings['unfilled-behavior'] !== 'search-by-title' ) { return; } // ++ improve the logic
     91
     92    if ( $unfilled && $settings['unfilled-behavior'] === 'search-by-title' ) { // ++-- && is_single( $queried_id ) doesn't work somehow
     93        $query = trim( get_the_title( $queried_id ) );
     94        $wp_query_args += [ 'orderby' => 'date', 'order' => 'DESC', 's' => $query ];
     95    }
    8796
    8897    $search = new \WP_Query( $wp_query_args );
    8998
    90     if ( !$search->have_posts() || !( $search->found_posts >= ( $settings['minimum-posts'] ?: 0 ) ) ) { return; }
     99    if ( !$search->have_posts() || !( $search->found_posts >= ( $settings['minimum-posts'] ?? 0 ?: 0 ) ) ) { return; }
    91100
    92101    $get_template = function($name, $is_part = true) {
  • fcp-posts-by-search-query/trunk/posts-by-query.php

    r2934823 r2944709  
    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.4
     5Version: 1.0.5
    66Requires at least: 5.8
    77Tested up to: 6.2
     
    4747    // !!title and description must be more like for printing to understans blah blah check out the competitors
    4848// after publishing add thumbnails and the preview page
    49 
     49// test for errors and warnings on empty values in settings
    5050// ++ if Posts by Search Query & Date become empty, the old query still prints what was found
    5151// ++ turn posts-by-query into a constant and avoid conflict with FCPPBK_SETT
  • fcp-posts-by-search-query/trunk/readme.txt

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