-
Notifications
You must be signed in to change notification settings - Fork 6
[MOOSE-377] Update related posts selection and taxonomy matching #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ trait Post_Data { | |||||||||||||||||||
| protected \WP_Post_Type|null $post_type_object = null; | ||||||||||||||||||||
| protected int|false $image_id = false; | ||||||||||||||||||||
| protected \WP_Term|null $primary_category = null; | ||||||||||||||||||||
| protected \WP_Term|null $display_term = null; | ||||||||||||||||||||
| protected string $post_title = ''; | ||||||||||||||||||||
| protected string $author_id = '0'; | ||||||||||||||||||||
| protected string $author = ''; | ||||||||||||||||||||
|
|
@@ -31,6 +32,7 @@ public function set_post( mixed $post_id ): void { | |||||||||||||||||||
| $this->post_type_object = get_post_type_object( $this->post_type ); | ||||||||||||||||||||
| $this->image_id = get_post_thumbnail_id( $this->post_id ); | ||||||||||||||||||||
| $this->primary_category = $this->get_primary_term( $this->post_id, Category::NAME ); | ||||||||||||||||||||
| $this->display_term = $this->primary_category; | ||||||||||||||||||||
| $this->post_title = get_the_title( $this->post_id ); | ||||||||||||||||||||
| $this->author_id = get_post_field( 'post_author', $this->post_id ); | ||||||||||||||||||||
| $this->date = get_the_date( 'M j, Y', $this->post_id ); | ||||||||||||||||||||
|
|
@@ -64,6 +66,37 @@ public function get_primary_category_name(): string { | |||||||||||||||||||
| return $this->has_primary_category() ? $this->primary_category->name : ''; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public function set_display_term_taxonomy( string $taxonomy ): void { | ||||||||||||||||||||
| if ( null === $this->post_id || 0 === $this->post_id || '' === $taxonomy ) { | ||||||||||||||||||||
| $this->display_term = null; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( Category::NAME === $taxonomy ) { | ||||||||||||||||||||
| $this->display_term = $this->primary_category; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $terms = get_the_terms( $this->post_id, $taxonomy ); | ||||||||||||||||||||
| if ( $terms && ! is_wp_error( $terms ) ) { | ||||||||||||||||||||
| $this->display_term = reset( $terms ) ?: null; | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add some context here? How we can have |
||||||||||||||||||||
|
|
||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $this->display_term = null; | ||||||||||||||||||||
|
Comment on lines
+82
to
+89
|
||||||||||||||||||||
| $terms = get_the_terms( $this->post_id, $taxonomy ); | |
| if ( $terms && ! is_wp_error( $terms ) ) { | |
| $this->display_term = reset( $terms ) ?: null; | |
| return; | |
| } | |
| $this->display_term = null; | |
| $this->display_term = $this->get_primary_term( $this->post_id, $taxonomy ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this. get_primary_term already falls back to exactly what you have here, it's possible you don't need this entire function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual selection queries don't set
posts_per_page, so WordPress will apply the default posts-per-page limit (often 10) and can truncate the selectedpost__inlist. Consider settingposts_per_pagetocount( $this->chosen_posts )(or at least a large enough value) whenpost__inis used so all manually chosen posts render.