| @@ 216-241 (lines=26) @@ | ||
| 213 | * |
|
| 214 | * @return array|object|null Database query results |
|
| 215 | */ |
|
| 216 | public function get_non_article_subjects( $object_id, $fields = '*', $status = null ) { |
|
| 217 | global $wpdb; |
|
| 218 | ||
| 219 | // The output fields. |
|
| 220 | $actual_fields = self::fields( $fields ); |
|
| 221 | ||
| 222 | $sql = $wpdb->prepare( |
|
| 223 | " |
|
| 224 | SELECT p.$actual_fields |
|
| 225 | FROM {$this->relation_table} r |
|
| 226 | INNER JOIN $wpdb->posts p |
|
| 227 | ON p.id = r.subject_id |
|
| 228 | " |
|
| 229 | // Add the status clause. |
|
| 230 | . self::and_status( $status ) |
|
| 231 | . self::inner_join_is_not_article() . |
|
| 232 | " |
|
| 233 | WHERE r.object_id = %d |
|
| 234 | AND p.post_type IN ( 'post', 'page', 'entity' ) |
|
| 235 | " |
|
| 236 | , |
|
| 237 | $object_id |
|
| 238 | ); |
|
| 239 | ||
| 240 | return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); |
|
| 241 | } |
|
| 242 | ||
| 243 | /** |
|
| 244 | * Get the entities referenced by the specified {@link WP_Post}. |
|
| @@ 256-282 (lines=27) @@ | ||
| 253 | * |
|
| 254 | * @return array|object|null Database query results |
|
| 255 | */ |
|
| 256 | public function get_objects( $subject_id, $fields = '*', $predicate = null, $status = null ) { |
|
| 257 | global $wpdb; |
|
| 258 | ||
| 259 | // The output fields. |
|
| 260 | $actual_fields = self::fields( $fields ); |
|
| 261 | ||
| 262 | $sql = $wpdb->prepare( |
|
| 263 | " |
|
| 264 | SELECT p.$actual_fields |
|
| 265 | FROM {$this->relation_table} r |
|
| 266 | INNER JOIN $wpdb->posts p |
|
| 267 | ON p.id = r.object_id |
|
| 268 | " |
|
| 269 | // Add the status clause. |
|
| 270 | . self::and_status( $status ) |
|
| 271 | . self::inner_join_is_not_article() |
|
| 272 | . " |
|
| 273 | WHERE r.subject_id = %d |
|
| 274 | AND p.post_type IN ( 'post', 'page', 'entity' ) |
|
| 275 | " |
|
| 276 | . self::and_predicate( $predicate ) |
|
| 277 | , |
|
| 278 | $subject_id |
|
| 279 | ); |
|
| 280 | ||
| 281 | return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); |
|
| 282 | } |
|
| 283 | ||
| 284 | /** |
|
| 285 | * Add the `post_status` clause. |
|