admin管理员组

文章数量:1404464

I've just spent 2 days on trying to pass/change an argument in a plugin's function but had no luck so far. Would anyone, please, show me the correct way or solution how to do that?

I need to be able to change value 'cat' => '44' with a shortcode to any other value written in that shortcode for instance [search cat="15"] would make the 'cat' => '15' in the function.

function search() {
    if ( isset( $_REQUEST['swpquery'] ) && ! empty( $_REQUEST['swpquery'] ) ) {

        $query = sanitize_text_field( $_REQUEST['swpquery'] );

    if ( class_exists( 'SearchWP' ) ) {
        // SearchWP powered search
        $posts = $this->searchwp( $query );
        $args = array(
            'post_type'        => 'any',      // We're limiting to a pre-set array of post IDs.
            'post_status'      => 'any',      // We're limiting to a pre-set array of post IDs.
            'post__in'         => $posts,
            'orderby'          => 'post__in',
            'suppress_filters' => true,
        );
    } else {
        // native WordPress search
        $args = array(
            's'           => $query,
            'post_status' => 'publish',
            'cat' => '44',
            'post_type'   => get_post_types( array(
                'public'              => true,
                'exclude_from_search' => false,
            ) ),
        );
    }

    $args['posts_per_page'] = $this->get_posts_per_page();

    $args = apply_filters( 'searchwp_live_search_query_args', $args );

    $this->show_results( $args );
}

// Short circuit to keep the overhead of an admin-ajax.php call to a minimum.
die();}

Thanks so much for any help.

本文标签: Edit plugin function with a hook