class-comment-meta.php
5 months ago
class-comment.php
5 months ago
class-meta.php
5 months ago
class-options.php
5 months ago
class-post-meta.php
5 months ago
class-post.php
5 months ago
class-terms.php
4 months ago
class-user-meta.php
5 months ago
class-user.php
5 months ago
class-post-meta.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Source\Core; |
| 4 | |
| 5 | use SearchRegex\Source; |
| 6 | use SearchRegex\Schema; |
| 7 | use SearchRegex\Sql; |
| 8 | |
| 9 | class Post_Meta extends Meta { |
| 10 | public function get_table_name() { |
| 11 | global $wpdb; |
| 12 | |
| 13 | return $wpdb->postmeta; |
| 14 | } |
| 15 | |
| 16 | public function get_meta_object_id() { |
| 17 | return 'post_id'; |
| 18 | } |
| 19 | |
| 20 | public function get_meta_table() { |
| 21 | return 'post'; |
| 22 | } |
| 23 | |
| 24 | public function get_meta_name() { |
| 25 | return __( 'Post Meta', 'search-regex' ); |
| 26 | } |
| 27 | |
| 28 | public function autocomplete( array $column, $value ) { |
| 29 | if ( $column['column'] === $this->get_meta_object_id() ) { |
| 30 | return Source\Autocomplete::get_post( $value, Sql\Value::column( 'ID' ), Sql\Value::column( 'post_title' ) ); |
| 31 | } |
| 32 | |
| 33 | return parent::autocomplete( $column, $value ); |
| 34 | } |
| 35 | |
| 36 | public function convert_result_value( Schema\Column $schema, $value ) { |
| 37 | if ( $schema->get_column() === 'post_id' ) { |
| 38 | $post = get_post( intval( $value, 10 ) ); |
| 39 | |
| 40 | if ( is_object( $post ) ) { |
| 41 | return $post->post_title; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return parent::convert_result_value( $schema, $value ); |
| 46 | } |
| 47 | } |
| 48 |