Not auto indexing
-
We’ve set up a cron job on our server that imports jobs from Broadbead from an XML file directly into the database. However these new jobs do not appear in the search until we manually go in and build the index again. I’m guessing that this is because the auto index normally kicks in when posts are added using the WordPress dashboard? Is there a way to schedule the plugin to build the index every hour anyway?
-
Can you set up your import to fire
wp_insert_post
hook for each post saved? That’s what Relevanssi uses to notice new posts. That would ensure compatibility with other plugins attached to that hook as well.Hi,
This appears to be in the code already:
// Insert Data in posts $page = array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_author' => 1, 'post_name' => strtolower( str_replace( ' ', '-', $job_title ) ), 'post_title' => $job_title, 'post_type' => 'jobs', 'post_date' => date('Y-m-d H:i:s'), 'post_parent' => '30' ); $postid = wp_insert_post( $page ); /*Insert Data in related post*/ add_post_meta($postid, 'data1', addslashes( $salary_from ) ) ;// Min-Salary add_post_meta($postid, 'data9', addslashes( $salary_to) ); // Max-Salary add_post_meta($postid, 'data10', addslashes( $salary_benefits ) ); // Benefits add_post_meta($postid, 'data12', addslashes( $job_location ) ); // Job Location $query_get_loc_id = " SELECT * FROM $wpdb->postmeta WHERE meta_key='data12' AND lower(meta_value) = '".strtolower(addslashes( $job_location ))."'"; $result_get_loc_id = mysql_query($query_get_loc_id); $row_get_loc_id = mysql_fetch_object($result_get_loc_id); if($row_get_loc_id) $job_location = $row_get_loc_id->meta_value; add_post_meta($postid, 'data13', addslashes( $job_description ) ); // Job Description add_post_meta($postid, 'data14', addslashes( $job_reference ) ); // Job Reference add_post_meta($postid, 'data15', addslashes( $job_qualification ) ); // Job Qualification add_post_meta($postid, 'data16', addslashes( $salary ) ); // ( Salary / Special ) add_post_meta($postid, 'data17', addslashes( $job_startdate ) ); // Job StartDate add_post_meta($postid, 'email', addslashes( $application_email ) ); // Application Email add_post_meta($postid, 'data19', addslashes( $salary_currency ) ); // Salary Currency add_post_meta($postid, 'data20', addslashes( $salary_per ) );// Salary Period add_post_meta($postid, 'highlighted', '0'); // Highlighted
Ok, that should trigger the Relevanssi indexing, but since all the meta data is added after the wp_insert_post() call, Relevanssi will not see that.
I would try adding this in the end after the last add_post_meta():
$post_obj = get_post($postid); do_action( 'wp_insert_post', $postid, $post_obj, true );
and see if that helps.
Still no joy I’m afraid, this is the full code after adding your code…
<?php include('wp-config.php'); /*FUNCTION FILE*/ function filter_category($cat){ $cat = str_replace("&","",strtolower ( $cat )); $cat = str_replace("&","",strtolower ( $cat )); $cat = str_replace(" ","-",strtolower ( $cat )); $cat = str_replace("--","-",strtolower ( $cat )); $cat = str_replace(",","",strtolower ( $cat )); return $cat; } // Function For get Category Id function get_category_id($cat_name){ global $wpdb; $sql_id ="SELECT term_id FROM ".$wpdb->terms." WHERE name='".$cat_name."'"; $result = mysql_query($sql_id); $get_term = mysql_fetch_object($result); return $get_term->term_id; } //function to replace htmlentity to in formate function broadbean_xml_convert($xml) { $xml = str_replace('£','£',$xml); preg_match_all('/%u(:alnum:{4})/', $xml, $a); foreach ($a[1] as $uniord) { $dec = hexdec($uniord); $utf = ''; if ($dec < 128) { $utf = chr($dec); } else if ($dec < 2048) { $utf = chr(192 + (($dec - ($dec % 64)) / 64)); $utf .= chr(128 + ($dec % 64)); } else { $utf = chr(224 + (($dec - ($dec % 4096)) / 4096)); $utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64)); $utf .= chr(128 + ($dec % 64)); } $xml = str_replace('%u'.$uniord, $utf, $xml); } $xml = str_replace('&','&',$xml); return urldecode($xml); } $YourFile = "https://www.bis-henderson.com/broadbeanjobpost.xml"; $broadbean_xml = stripcslashes($_REQUEST['file']); $data = broadbean_xml_convert($broadbean_xml); // Write XML File and update $file = fopen( 'broadbeanjobpost.xml', "w") or exit("Unable to open file!"); fwrite($file, $data); fclose($file); /* End FUNCTION FILE */ $xml = simplexml_load_file($YourFile); foreach($xml->children() as $child) { switch ($child->getName()) { case command: $command = $child; break; case username: $username = $child; break; case password: $password = $child; break; case contact_email: $contact_email = $child; break; case contact_telephone: $contact_telephone = $child; break; case contact_url: $contact_url = $child; break; case days_to_advertise: $days_to_advertise = $child; break; case application_email: $application_email = $child; break; case application_url: $application_url = $child; break; case job_reference: $job_reference = $child; break; case job_category: $job_category = str_replace("&","&", trim($child) ); $job_category = str_replace("&","&", trim($job_category) ); break; case job_title: $job_title = $child; break; case job_type: $job_type = $child; break; case job_duration: $job_duration = $child; break; case job_startdate: $job_startdate = $child; break; case job_skills: $job_skills = $child; break; case job_qualification: $job_qualification = $child; break; case job_description: $job_description = $child; break; case job_location: $job_location = str_replace("&","&", trim($child)); $job_location = str_replace("&","and", trim($job_location)); break; case job_industry: $job_industry = $child; break; case salary_currency: $salary_currency = trim($child); break; case salary_from: $salary_from = trim($child); break; case salary_to: $salary_to = trim($child); break; case salary_per: $salary_per = trim($child); break; case salary_benefits: $salary_benefits = $child; break; case salary: $salary = $child; break; default: break; } } if( ( strtolower($username) == strtolower('Mark Botham') ) && ( strtolower($password) == strtolower('srilanka123') ) ){ // To check is post is already present or not with Referance Number $query_get_post_id = " SELECT post_id FROM $wpdb->postmeta WHERE meta_key='data14' AND lower(meta_value) = '".strtolower(addslashes( $job_reference ))."'"; $result_get_post_id = mysql_query($query_get_post_id); $row_get_post_id = mysql_fetch_object($result_get_post_id); if($row_get_post_id) $flag = TRUE; /* digits only, no dots */ function is_sal($element) { if(strtolower($element) == "negotiable"){ return $element; } $element= str_replace(',', '', $element); return !preg_match ("/[^0-9]/", $element); } if( !(is_sal($salary_from)) || !(is_sal($salary_to)) ) $error = "Please add Salary in proper formate "; // To Add Job if( strtolower ( $command ) == 'add'){ if($job_category==""){ if(empty($error)) $error = "Category is empty"; } $theCatId = get_term_by( 'slug', filter_category($job_category), 'jobman_category' ); $catid = $theCatId->term_taxonomy_id; echo $catid; if(empty($catid)){ if(empty($error)) $error = "Category Is Not Present In System"; } $args = array( 'orderby' => 'post_title', 'order' => 'ASC', 'post_type' => 'location', 'post_status' => 'publish', 'numberposts' => 9999 ); $location_list = get_posts( $args ); if( count( $location_list ) > 0 ) { foreach( $location_list as $loc ) { if(strtolower($job_location) == strtolower($loc->post_title) ){ $location_is_present = 1; break; } } } if($location_is_present!=1){ if(empty($error)) $error = "Location is not Present System"; } $currencies = array( 'AUD' => array('name' => "Australian Dollar", 'symbol' => "A$", 'ASCII' => "A$",'ISO'=>'AUD'), 'CAD' => array('name' => "Canadian Dollar", 'symbol' => "$", 'ASCII' => "$",'ISO'=>'CAD'), 'EUR' => array('name' => "Euro", 'symbol' => "?", 'ASCII' => "",'ISO'=>'EUR'), 'JPY' => array('name' => "Japanese Yen", 'symbol' => "¥", 'ASCII' => "¥",'ISO'=>'JPY'), 'MXN' => array('name' => "Mexican Peso", 'symbol' => "$", 'ASCII' => "$",'ISO'=>'MXN'), 'NZD' => array('name' => "New Zealand Dollar", 'symbol' => "$", 'ASCII' => "$",'ISO'=>'NZD'), 'GBP' => array('name' => "Pound Sterling", 'symbol' => "£", 'ASCII' => "£",'ISO'=>'GBP'), 'SGD' => array('name' => "Singapore Dollar", 'symbol' => "$", 'ASCII' => "$",'ISO'=>'SGD'), 'CHF' => array('name' => "Swiss Franc", 'symbol' => "CHF", 'ASCII' => "",'ISO'=>'CHF'), 'USD' => array('name' => "U.S. Dollar", 'symbol' => "$", 'ASCII' => "$",'ISO'=>'USD') ); foreach($currencies as $currency){ if (strtolower($salary_currency) == strtolower($currency['ISO']) ) { $cur = 1; break; } } if($cur!=1) $error = "Currency is not present In system"; $period = array('Annum','Month','Week','Day'); foreach($period as $per){ if ( strtolower($salary_per) != strtolower($per) ) $salary_per = "Annum"; } if($flag){ if(empty($error)) $error ="<strong>oops!</strong> This job is already present..."; } // Check If is any error is present or not if(!$error){ // Insert Data in posts $page = array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_author' => 1, 'post_name' => strtolower( str_replace( ' ', '-', $job_title ) ), 'post_title' => $job_title, 'post_type' => 'jobs', 'post_date' => date('Y-m-d H:i:s'), 'post_parent' => '30' ); $postid = wp_insert_post( $page ); /*Insert Data in related post*/ add_post_meta($postid, 'data1', addslashes( $salary_from ) ) ;// Min-Salary add_post_meta($postid, 'data9', addslashes( $salary_to) ); // Max-Salary add_post_meta($postid, 'data10', addslashes( $salary_benefits ) ); // Benefits add_post_meta($postid, 'data12', addslashes( $job_location ) ); // Job Location $query_get_loc_id = " SELECT * FROM $wpdb->postmeta WHERE meta_key='data12' AND lower(meta_value) = '".strtolower(addslashes( $job_location ))."'"; $result_get_loc_id = mysql_query($query_get_loc_id); $row_get_loc_id = mysql_fetch_object($result_get_loc_id); if($row_get_loc_id) $job_location = $row_get_loc_id->meta_value; add_post_meta($postid, 'data13', addslashes( $job_description ) ); // Job Description add_post_meta($postid, 'data14', addslashes( $job_reference ) ); // Job Reference add_post_meta($postid, 'data15', addslashes( $job_qualification ) ); // Job Qualification add_post_meta($postid, 'data16', addslashes( $salary ) ); // ( Salary / Special ) add_post_meta($postid, 'data17', addslashes( $job_startdate ) ); // Job StartDate add_post_meta($postid, 'email', addslashes( $application_email ) ); // Application Email add_post_meta($postid, 'data19', addslashes( $salary_currency ) ); // Salary Currency add_post_meta($postid, 'data20', addslashes( $salary_per ) );// Salary Period add_post_meta($postid, 'highlighted', '0'); // Highlighted // Relevanssi Code $post_obj = get_post($postid); do_action( 'wp_insert_post', $postid, $post_obj, true ); // Insert Data in term_relationships global $wpdb; $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $postid, 'term_taxonomy_id' => $catid ), array( '%s', '%s' ) ); $job_array = get_post($postid); $post_title = $job_array->post_title; $post_link = $job_array->guid; $success = "Job ( <strong>".$post_title."</strong> ) Added successfully \n"; $success .= "<a href='".$post_link."'>".$post_title."</a>"; } }elseif( strtolower ( $command ) == 'delete' ){ // To Delete the Job Detail if($flag){ $post_array = get_post($row_get_post_id->post_id); $post_title = $post_array->post_title; $success = "Job( ".$post_title." ) successfully deleted \n"; wp_delete_post($row_get_post_id->post_id); }else{ $error = "There is No Job having with Reference Number ".$job_reference ; } }elseif( (strtolower ( $command ) != 'add') || (strtolower ( $command ) != 'delete') ){ $error = "<strong>".$command ."</strong>is Wrong Command"; } }else{ $error = "You don't have permission to Post Job"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Bis JobPosting</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <style type="text/css"> body{ text-align:center; } .error{ border:1px solid #ff0000; padding:10px 10px; margin:0 auto; width:350px; color:#ff0000; } .success{ border:1px solid #96C440; padding:10px 10px; margin:0 auto; width:350px; color:#96C440; } .heading a { color: #3F97D7; font-size: 32px; text-decoration: none; } a { color: #0C6FB3; text-decoration: blink; text-decoration: none; } </style> </head> <body> <div class="heading"><a href="/">Bis Henderson</a></div> <?php if($error){ echo "<div class='error'>".$error."</div>"; }elseif($success){ echo "<div class='success'>".$success."</div>"; }?> </body> </html>
Are you sure that the wp_insert_post action is triggered properly? I’d check that. Create a function action on the hook that fires you an email, or something like that, and see if it happens.
- The topic ‘Not auto indexing’ is closed to new replies.