php [MarketPress - Upfront] - 产品搜索

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [MarketPress - Upfront] - 产品搜索相关的知识,希望对你有一定的参考价值。

<?php
/**
* Plugin Name: [MarketPress - Upfront] - Products search
* Plugin URI: https://premium.wpmudev.org/
* Description: MarketPress Products search for Upfront
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_filter( 'upfront-posts-get_markup-before', function( $status ){

	$queried_type = $query->get( 'post_type' );
	$is_product_queried = is_array( $queried_type ) ? in_array( MP_Product::get_post_type(), $queried_type ) : MP_Product::get_post_type() == $queried_type;
	
    	if (is_search() && !is_admin() && $is_product_queried ) {
        	$query->set( 's', get_query_var('s') );
    	}

	return $query;

}, 0 );


function wpmudev_mp_uf_posts_where( $where ){

	remove_action( 'posts_where', 'wpmudev_mp_uf_posts_where', 10 );

	global $wpdb;
	$s = sanitize_text_field( $_GET['s'] );
	$post_type = MP_Product::get_post_type();

	$where = " AND {$wpdb->posts}.post_type = '{$post_type}' AND {$wpdb->posts}.post_status = 'publish' AND ( {$wpdb->posts}.post_title LIKE '%{$s}%' OR {$wpdb->posts}.post_content LIKE '%{$s}%' OR {$wpdb->posts}.post_excerpt LIKE '%{$s}%' )";

	return $where;
}



function wpmudev_look_only_products($query) {

    if (is_search() && !is_admin() && MP_Product::get_post_type() == $query->get( 'post_type' ) ) {        
        $query->set( 's', get_query_var('s') );
    }

	return $query;

}
 
add_filter('pre_get_posts', 'wpmudev_look_only_products');

以上是关于php [MarketPress - Upfront] - 产品搜索的主要内容,如果未能解决你的问题,请参考以下文章

php [MarketPress] - 出口订单

php [MarketPress] - 重复产品

php [MarketPress] - 过滤地址字段

php [MarketPress - Upfront] - 产品搜索

php 强制MarketPress变化模态100%宽度

php [MarketPress] - 使用domDocument过滤价格html