PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / repositories / primary-term-repository.php

primary-term-repository.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at src/repositories/primary-term-repository.php

50 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Repositories;
4
5 use Yoast\WP\Lib\Model;
6 use Yoast\WP\Lib\ORM;
7 use Yoast\WP\SEO\Models\Primary_Term;
8
9 /**
10 * Class Primary_Term_Repository.
11 */
12 class Primary_Term_Repository {
13
14 /**
15 * Starts a query for this repository.
16 *
17 * @return ORM
18 */
19 public function query() {
20 return Model::of_type( 'Primary_Term' );
21 }
22
23 /**
24 * Retrieves a primary term by a post ID and taxonomy.
25 *
26 * @param int $post_id The post the indexable is based upon.
27 * @param string $taxonomy The taxonomy the indexable belongs to.
28 * @param bool $auto_create Optional. Creates an indexable if it does not exist yet.
29 *
30 * @return Primary_Term|null Instance of a primary term.
31 */
32 public function find_by_post_id_and_taxonomy( $post_id, $taxonomy, $auto_create = true ) {
33 /**
34 * Instance of the primary term.
35 *
36 * @var Primary_Term $primary_term_indexable
37 */
38 $primary_term_indexable = $this->query()
39 ->where( 'post_id', $post_id )
40 ->where( 'taxonomy', $taxonomy )
41 ->find_one();
42
43 if ( $auto_create && ! $primary_term_indexable ) {
44 $primary_term_indexable = $this->query()->create();
45 }
46
47 return $primary_term_indexable;
48 }
49 }
50