function delete_post($post_id) { if (is_object($post_id)) { $post = $post_id; } else { $post = get_post($post_id); } if ($post == null || !in_array($post->post_type, Config::types())) { return; } Indexer::delete($post); }
public function testDelete() { update_option('fields', array('field1' => 1, 'field2' => 1)); register_post_type('post'); $post = (object) array('post_type' => 'post', 'ID' => 1, 'field1' => 'value1', 'field2' => 'value2'); Indexer::addOrUpdate($post); $this->index->refresh(); $this->assertEquals(1, $this->index->count(new \Elastica\Query(array('query' => array('bool' => array('must' => array(array('match' => array('_id' => 1)), array('match' => array('field1' => 'value1')), array('match' => array('field2' => 'value2'))))))))); Indexer::delete($post); $this->index->refresh(); $this->assertEquals(0, $this->index->count()); }