• Resolved aleks

    (@aleks683)


    Hi, I previously used this code:

    <?php
    	new WPkonsulentSearchById();
    	class WPkonsulentSearchById
    	{
    		function __construct()
    		{
    			add_filter('posts_where', array($this, 'posts_where'));
    		}
    		function posts_where($where)
    		{
    			if(is_search())
    			{
    				$s = $_GET['s'];
    				
    				if(!empty($s))
    				{
    					if(is_numeric($s))
    					{
    						global $wpdb;
    						$where = str_replace('(' . $wpdb->posts . '.post_title LIKE', '(' . $wpdb->posts . '.ID = ' . $s . ') OR (' . $wpdb->posts . '.post_title LIKE', $where);
    					}
    					elseif(preg_match("/^(\d+)(,\s*\d+)*\$/", $s)) // string of post IDs
    					{
    						global $wpdb;
    						$where = str_replace('(' . $wpdb->posts . '.post_title LIKE', '(' . $wpdb->posts . '.ID in (' . $s . ')) OR (' . $wpdb->posts . '.post_title LIKE', $where);
    					}
    				}
    			}
    			
    			return $where;
    		}
    	}
    ?>

    It is to search for products by id. After activating your plugin, the code stopped working. How to combine them? Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    You want to search only by ID? Maybe search by SKU solve your problem too?

    Thread Starter aleks

    (@aleks683)

    I need to look for the standard (title) + id. The above code is ideal. But it does not work with your plugin. How to edit the code so that it works with the plugin?

    Thread Starter aleks

    (@aleks683)

    ILLID help me please. Because of this code, I can not activate the plugin. The entire structure of the site is based on search through ID. Advanced Woo Search is suitable for my store.

    Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Sorry for the long response.

    Please add following code to your theme functions.php file

    add_filter( 'aws_indexed_title', 'aws_indexed_title', 10, 2 );
    
    function aws_indexed_title( $title, $id ) {
        $title = $title . ' ' . $id;
        return $title;
    }

    Also after this please go to plugin settings page and click ‘Reindex table’ button.
    Now search by ID must be available for you.

    Thread Starter aleks

    (@aleks683)

    Hello,
    Thank you very much, everything works perfect!

    Plugin Author ILLID

    (@mihail-barinov)

    Glad to help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Search by ID’ is closed to new replies.