Search code examples
phpopencart

How to check if SEO keyword already exist when edit product/category - Opencart


When i edit product/category how can i check if seo keyword already exist in database ? i need it for custom use


Solution

  • if you want to check by programmatically then you can use following function for check, if SEO is exist or not. this will work in all version.

    function check_seo($keyword = ''){
        if(version_compare(VERSION, '3.0.0.0', '<')){ // below 3.0.0.0 version
            $SQL = "SELECT * FROM " . DB_PREFIX . "url_alias WHERE `keyword` LIKE '" . $this->db->escape($keyword)."'";
        }else{
            $SQL = "SELECT * FROM " . DB_PREFIX . "seo_url WHERE `keyword` LIKE '" . $this->db->escape($keyword)."'";
        }
        $found =  $this->db->query($SQL." LIMIT 1")->num_rows;
    
        if($found){
            // SEO already exists
        }else{
            // You can use this $keyword for SEO
        }
    }
    

    like if you want to check only for mac category SEO then check below Query and image,

    Query :

    SELECT * FROM `oc_url_alias` WHERE `query` LIKE 'category_id=%' AND `keyword` LIKE 'mac'
    

    enter image description here