Optimize post ID accesses

This commit is contained in:
Tetrakern 2024-05-17 17:46:54 +02:00
parent 74722edea8
commit 0355631d8a
21 changed files with 158 additions and 135 deletions

View File

@ -198,9 +198,10 @@ if ( ! function_exists( 'fictioneer_get_schema_node_article' ) ) {
function fictioneer_get_schema_node_article( $type, $description, $post = null, $image_data = null, $no_cat = false ) {
// Setup
$post = empty( $post ) ? get_queried_object() : $post;
$post_id = $post->ID;
$author = get_the_author_meta( 'display_name', $post->post_author );
$tags = get_the_tags( $post->ID );
$categories = $no_cat ? [] : get_the_category( $post->ID );
$tags = get_the_tags( $post_id );
$categories = $no_cat ? [] : get_the_category( $post_id );
$taxonomies = is_array( $tags ) ? array_merge( $categories, $tags ) : $categories;
$keywords = [];
@ -215,9 +216,9 @@ if ( ! function_exists( 'fictioneer_get_schema_node_article' ) ) {
$article_node = array(
'@type' => $type,
'@id' => "#article",
'headline' => fictioneer_get_safe_title( $post->ID, 'seo-schema-article-node' ),
'headline' => fictioneer_get_safe_title( $post_id, 'seo-schema-article-node' ),
'description' => $description,
'url' => get_the_permalink( $post->ID ),
'url' => get_the_permalink( $post_id ),
'author' => array(
'@type' => 'Person',
'url' => get_site_url( null, '', 'https' ),
@ -226,8 +227,8 @@ if ( ! function_exists( 'fictioneer_get_schema_node_article' ) ) {
'isPartOf' => array( '@id' => "#webpage" ),
'mainEntityOfPage' => array( '@id' => "#webpage" ),
'inLanguage' => get_bloginfo( 'language' ),
'datePublished' => get_the_date( 'c', $post->ID ),
'dateModified' => get_the_modified_date( 'c', $post->ID )
'datePublished' => get_the_date( 'c', $post_id ),
'dateModified' => get_the_modified_date( 'c', $post_id )
);
// Account for primary image (if any)

View File

@ -147,7 +147,8 @@ function fictioneer_create_sitemap() {
);
foreach( $pages as $post ) {
$template = get_page_template_slug( $post->ID );
$post_id = $post->ID;
$template = get_page_template_slug( $post_id );
$template_excludes = ['user-profile.php', 'singular-bookmarks.php', 'singular-bookshelf.php', 'singular-bookshelf-ajax.php'];
$template_excludes = apply_filters( 'fictioneer_filter_sitemap_page_template_excludes', $template_excludes );
@ -155,8 +156,8 @@ function fictioneer_create_sitemap() {
continue;
}
$lastmod = get_the_modified_date( 'c', $post->ID );
$sitemap .= fictioneer_url_node( get_permalink( $post->ID ), $lastmod, 'monthly' );
$lastmod = get_the_modified_date( 'c', $post_id );
$sitemap .= fictioneer_url_node( get_permalink( $post_id ), $lastmod, 'monthly' );
}
// Blogs
@ -212,14 +213,16 @@ function fictioneer_create_sitemap() {
);
foreach ( $stories as $post ) {
if ( get_post_meta( $post->ID, 'fictioneer_story_hidden', true ) ) {
$post_id = $post->ID;
if ( get_post_meta( $post_id, 'fictioneer_story_hidden', true ) ) {
continue;
}
$lastmod = get_the_modified_date( 'c', $post->ID );
$status = get_post_meta( $post->ID, 'fictioneer_story_status', true );
$lastmod = get_the_modified_date( 'c', $post_id );
$status = get_post_meta( $post_id, 'fictioneer_story_status', true );
$frequency = $status == 'Ongoing' ? 'weekly' : 'monthly';
$sitemap .= fictioneer_url_node( get_permalink( $post->ID ), $lastmod, $frequency );
$sitemap .= fictioneer_url_node( get_permalink( $post_id ), $lastmod, $frequency );
}
// Chapters

View File

@ -226,7 +226,8 @@ function fictioneer_log_story_chapter_status_changes( $new_status, $old_status,
}
// Story?
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$post_id = $post->ID;
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
if ( empty( $story_id ) ) {
return;
@ -244,8 +245,8 @@ function fictioneer_log_story_chapter_status_changes( $new_status, $old_status,
time(),
sprintf(
_x( '#%s privated: %s.', 'Story changelog chapter removed.', 'fictioneer' ),
$post->ID,
fictioneer_get_safe_title( $post->ID, true, 'admin-log-status-change-publish_to_private' )
$post_id,
fictioneer_get_safe_title( $post_id, true, 'admin-log-status-change-publish_to_private' )
)
);
@ -258,8 +259,8 @@ function fictioneer_log_story_chapter_status_changes( $new_status, $old_status,
time(),
sprintf(
_x( '#%s unprivated: %s.', 'Story changelog chapter removed.', 'fictioneer' ),
$post->ID,
fictioneer_get_safe_title( $post->ID, true, 'admin-log-status-change-private_to_publish' )
$post_id,
fictioneer_get_safe_title( $post_id, true, 'admin-log-status-change-private_to_publish' )
)
);

View File

@ -3016,23 +3016,24 @@ function fictioneer_get_post_patreon_data( $post = null ) {
// Post?
$post = $post ?? get_post();
$post_id = $post->ID;
if ( ! $post ) {
return null;
}
// Check cache
if ( isset( $cache[ $post->ID ] ) ) {
return $cache[ $post->ID ];
if ( isset( $cache[ $post_id ] ) ) {
return $cache[ $post_id ];
}
// Setup
$global_tiers = get_option( 'fictioneer_patreon_global_lock_tiers', [] ) ?: [];
$global_amount_cents = get_option( 'fictioneer_patreon_global_lock_amount', 0 ) ?: 0;
$global_lifetime_amount_cents = get_option( 'fictioneer_patreon_global_lock_lifetime_amount', 0 ) ?: 0;
$post_tiers = get_post_meta( $post->ID, 'fictioneer_patreon_lock_tiers', true );
$post_tiers = get_post_meta( $post_id, 'fictioneer_patreon_lock_tiers', true );
$post_tiers = is_array( $post_tiers ) ? $post_tiers : [];
$post_amount_cents = absint( get_post_meta( $post->ID, 'fictioneer_patreon_lock_amount', true ) );
$post_amount_cents = absint( get_post_meta( $post_id, 'fictioneer_patreon_lock_amount', true ) );
$check_tiers = array_merge( $global_tiers, $post_tiers );
$check_tiers = array_unique( $check_tiers );
$check_amount_cents = $post_amount_cents > 0 ? $post_amount_cents : $global_amount_cents;
@ -3049,7 +3050,7 @@ function fictioneer_get_post_patreon_data( $post = null ) {
);
// Cache
$cache[ $post->ID ] = $data;
$cache[ $post_id ] = $data;
// Return
return $data;

View File

@ -123,10 +123,11 @@ $pag_args = array(
$query->the_post();
// Setup
$story_id = ( $post->post_type === 'fcn_story' ) ? $post->ID : null;
$title = fictioneer_get_safe_title( $post->ID, 'card-article' );
$post_id = $post->ID;
$story_id = ( $post->post_type === 'fcn_story' ) ? $post_id : null;
$title = fictioneer_get_safe_title( $post_id, 'card-article' );
$permalink = get_permalink();
$categories = wp_get_post_categories( $post->ID );
$categories = wp_get_post_categories( $post_id );
$tags = get_the_tags();
$fandoms = get_the_terms( $post, 'fcn_fandom' );
$characters = get_the_terms( $post, 'fcn_character' );
@ -135,7 +136,7 @@ $pag_args = array(
// Chapter story?
if ( $post->post_type === 'fcn_chapter' ) {
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
}
// Extra classes
@ -163,7 +164,7 @@ $pag_args = array(
}
// Start HTML ---> ?>
<li class="post-<?php echo $post->ID; ?> card _article <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card _article <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<article class="card__body _article polygon">
<div class="card__main _article">
@ -172,7 +173,7 @@ $pag_args = array(
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $title,
'classes' => 'card__image _article cell-img',
'permalink' => $permalink,

View File

@ -18,14 +18,15 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'card-chapter' );
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'card-chapter' );
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
$story_post = get_post( $story_id );
$story_unpublished = get_post_status( $story_id ) !== 'publish';
$story_data = $story_id ? fictioneer_get_story_data( $story_id, false ) : null; // Does not refresh comment count!
$chapter_rating = get_post_meta( $post->ID, 'fictioneer_chapter_rating', true );
$chapter_rating = get_post_meta( $post_id, 'fictioneer_chapter_rating', true );
$story_thumbnail_url_full = $story_id ? get_the_post_thumbnail_url( $story_id, 'full' ) : null;
$text_icon = get_post_meta( $post->ID, 'fictioneer_chapter_text_icon', true );
$text_icon = get_post_meta( $post_id, 'fictioneer_chapter_text_icon', true );
$excerpt = fictioneer_get_forced_excerpt( $post, 512, true );
$card_classes = [];
@ -43,9 +44,9 @@ if (
}
if ( ! get_option( 'fictioneer_hide_taxonomies_on_chapter_cards' ) ) {
$fandoms = get_the_terms( $post->ID, 'fcn_fandom' );
$characters = get_the_terms( $post->ID, 'fcn_character' );
$genres = get_the_terms( $post->ID, 'fcn_genre' );
$fandoms = get_the_terms( $post_id, 'fcn_fandom' );
$characters = get_the_terms( $post_id, 'fcn_character' );
$genres = get_the_terms( $post_id, 'fcn_genre' );
}
// Flags
@ -82,10 +83,10 @@ $thumbnail_args = array(
?>
<li
id="chapter-card-<?php echo $post->ID; ?>"
class="post-<?php echo $post->ID; ?> card _large _chapter <?php echo implode( ' ', $card_classes ); ?>"
id="chapter-card-<?php echo $post_id; ?>"
class="post-<?php echo $post_id; ?> card _large _chapter <?php echo implode( ' ', $card_classes ); ?>"
data-story-id="<?php echo $story_id; ?>"
data-check-id="<?php echo $post->ID; ?>"
data-check-id="<?php echo $post_id; ?>"
data-unavailable="<?php esc_attr_e( 'Unavailable', 'fictioneer' ); ?>"
<?php echo $card_attributes; ?>
>
@ -101,7 +102,7 @@ $thumbnail_args = array(
<h3 class="card__title">
<a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php
$list_title = wp_strip_all_tags( get_post_meta( $post->ID, 'fictioneer_chapter_list_title', true ) );
$list_title = wp_strip_all_tags( get_post_meta( $post_id, 'fictioneer_chapter_list_title', true ) );
$list_title = trim( $list_title );
if ( ! empty( $post->post_password ) ) {
@ -120,7 +121,7 @@ $thumbnail_args = array(
<?php
if ( ! empty( $story_id ) && ! empty( $story_data ) ) {
echo fictioneer_get_card_controls( $story_id, $post->ID );
echo fictioneer_get_card_controls( $story_id, $post_id );
}
?>
@ -158,7 +159,7 @@ $thumbnail_args = array(
'<a href="%1$s" title="%2$s" class="card__text-icon cell-img"><span class="text-icon">%3$s</span></a>',
get_permalink(),
esc_attr( $title ),
get_post_meta( $post->ID, 'fictioneer_chapter_text_icon', true )
get_post_meta( $post_id, 'fictioneer_chapter_text_icon', true )
);
}
@ -233,7 +234,7 @@ $thumbnail_args = array(
$footer_items['words'] = '<i class="card-footer-icon fa-solid fa-font" title="' .
esc_attr__( 'Words', 'fictioneer' ) . '"></i> ' .
fictioneer_shorten_number( fictioneer_get_word_count( $post->ID ) );
fictioneer_shorten_number( fictioneer_get_word_count( $post_id ) );
if ( ( $args['orderby'] ?? 0 ) === 'date' ) {
$footer_items['publish_date'] = '<i class="card-footer-icon fa-solid fa-clock" title="' .

View File

@ -17,11 +17,12 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$list_title = trim( get_post_meta( $post->ID, 'fictioneer_collection_list_title', true ) );
$title = empty( $list_title ) ? fictioneer_get_safe_title( $post->ID, 'card-collection' ) : $list_title;
$description = fictioneer_get_content_field( 'fictioneer_collection_description', $post->ID );
$statistics = fictioneer_get_collection_statistics( $post->ID );
$items = get_post_meta( $post->ID, 'fictioneer_collection_items', true );
$post_id = $post->ID;
$list_title = trim( get_post_meta( $post_id, 'fictioneer_collection_list_title', true ) );
$title = empty( $list_title ) ? fictioneer_get_safe_title( $post_id, 'card-collection' ) : $list_title;
$description = fictioneer_get_content_field( 'fictioneer_collection_description', $post_id );
$statistics = fictioneer_get_collection_statistics( $post_id );
$items = get_post_meta( $post_id, 'fictioneer_collection_items', true );
$items = empty( $items ) ? [] : $items;
$card_classes = [];
@ -39,9 +40,9 @@ if (
}
if ( ! get_option( 'fictioneer_hide_taxonomies_on_collection_cards' ) ) {
$fandoms = get_the_terms( $post->ID, 'fcn_fandom' );
$characters = get_the_terms( $post->ID, 'fcn_character' );
$genres = get_the_terms( $post->ID, 'fcn_genre' );
$fandoms = get_the_terms( $post_id, 'fcn_fandom' );
$characters = get_the_terms( $post_id, 'fcn_character' );
$genres = get_the_terms( $post_id, 'fcn_genre' );
}
// Flags
@ -96,7 +97,7 @@ $thumbnail_args = array(
?>
<li id="collection-card-<?php echo $post->ID; ?>" class="post-<?php echo $post->ID; ?> card _large _collection <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li id="collection-card-<?php echo $post_id; ?>" class="post-<?php echo $post_id; ?> card _large _collection <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main _grid _large">

View File

@ -15,7 +15,8 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'card-page' );
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'card-page' );
$comments_number = get_comments_number();
$card_classes = [];
@ -44,7 +45,7 @@ $thumbnail_args = array(
?>
<li id="post-card-<?php echo $post->ID; ?>" class="post-<?php echo $post->ID; ?> card _large _page <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li id="post-card-<?php echo $post_id; ?>" class="post-<?php echo $post_id; ?> card _large _page <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main _grid _large">

View File

@ -15,9 +15,10 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'card-post' );
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'card-post' );
$tags = get_the_tags();
$categories = wp_get_post_categories( $post->ID );
$categories = wp_get_post_categories( $post_id );
$card_classes = [];
// Extra classes
@ -45,7 +46,7 @@ $thumbnail_args = array(
?>
<li id="post-card-<?php echo $post->ID; ?>" class="post-<?php echo $post->ID; ?> card _large _post <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li id="post-card-<?php echo $post_id; ?>" class="post-<?php echo $post_id; ?> card _large _post <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main _grid _large">

View File

@ -17,13 +17,14 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'card-recommendation' );
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'card-recommendation' );
$links = array_merge(
fictioneer_url_list_to_array( get_post_meta( $post->ID, 'fictioneer_recommendation_urls', true ) ),
fictioneer_url_list_to_array( get_post_meta( $post->ID, 'fictioneer_recommendation_support', true ) )
fictioneer_url_list_to_array( get_post_meta( $post_id, 'fictioneer_recommendation_urls', true ) ),
fictioneer_url_list_to_array( get_post_meta( $post_id, 'fictioneer_recommendation_support', true ) )
);
$excerpt = get_the_excerpt();
$one_sentence = get_post_meta( $post->ID, 'fictioneer_recommendation_one_sentence', true );
$one_sentence = get_post_meta( $post_id, 'fictioneer_recommendation_one_sentence', true );
$card_classes = [];
// Taxonomies
@ -40,9 +41,9 @@ if (
}
if ( ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_cards' ) ) {
$fandoms = get_the_terms( $post->ID, 'fcn_fandom' );
$characters = get_the_terms( $post->ID, 'fcn_character' );
$genres = get_the_terms( $post->ID, 'fcn_genre' );
$fandoms = get_the_terms( $post_id, 'fcn_fandom' );
$characters = get_the_terms( $post_id, 'fcn_character' );
$genres = get_the_terms( $post_id, 'fcn_genre' );
}
// Flags
@ -77,7 +78,7 @@ $thumbnail_args = array(
?>
<li id="recommendation-card-<?php echo $post->ID; ?>" class="post-<?php echo $post->ID; ?> card _recommendation _large _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li id="recommendation-card-<?php echo $post_id; ?>" class="post-<?php echo $post_id; ?> card _recommendation _large _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main _grid _large">
@ -110,7 +111,7 @@ $thumbnail_args = array(
count( $links ) > 3 ? '_3-4' : '_4-4',
sprintf(
_x( 'by %s —', 'Large card: by {Author} —.', 'fictioneer' ),
get_post_meta( $post->ID, 'fictioneer_recommendation_author', true )
get_post_meta( $post_id, 'fictioneer_recommendation_author', true )
),
strlen( $one_sentence ) < strlen( $excerpt ) ? $excerpt : wp_strip_all_tags( $one_sentence, true )
);

View File

@ -19,13 +19,14 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$story = fictioneer_get_story_data( $post->ID );
$story_link = ( $story['redirect'] ?? 0 ) ?: get_permalink( $post->ID );
$post_id = $post->ID;
$story = fictioneer_get_story_data( $post_id );
$story_link = ( $story['redirect'] ?? 0 ) ?: get_permalink( $post_id );
$latest = $args['show_latest'] ?? false;
$chapter_ids = array_slice( $story['chapter_ids'], $latest ? -3 : 0, 3, true ); // Does not include hidden or non-chapters
$chapter_count = count( $chapter_ids );
$excerpt = fictioneer_first_paragraph_as_excerpt(
fictioneer_get_content_field( 'fictioneer_story_short_description', $post->ID )
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
);
$excerpt = empty( $excerpt ) ? __( 'No description provided yet.', 'fictioneer' ) : $excerpt;
$tags = false;
@ -42,7 +43,7 @@ if (
$hide_author = $args['hide_author'] ?? false && ! get_option( 'fictioneer_show_authors' );
$show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' ) && ( $story['has_taxonomies'] || $tags );
$is_sticky = FICTIONEER_ENABLE_STICKY_CARDS &&
get_post_meta( $post->ID, 'fictioneer_story_sticky', true ) && ! is_search() && ! is_archive();
get_post_meta( $post_id, 'fictioneer_story_sticky', true ) && ! is_search() && ! is_archive();
// Extra classes
if ( $is_sticky ) {
@ -74,10 +75,10 @@ $thumbnail_args = array(
?>
<li
id="story-card-<?php echo $post->ID; ?>"
class="post-<?php echo $post->ID; ?> card _large _story <?php echo implode( ' ', $card_classes ); ?>"
data-story-id="<?php echo $post->ID; ?>"
data-check-id="<?php echo $post->ID; ?>"
id="story-card-<?php echo $post_id; ?>"
class="post-<?php echo $post_id; ?> card _large _story <?php echo implode( ' ', $card_classes ); ?>"
data-story-id="<?php echo $post_id; ?>"
data-check-id="<?php echo $post_id; ?>"
<?php echo $card_attributes; ?>
>
<div class="card__body polygon">
@ -98,7 +99,7 @@ $thumbnail_args = array(
echo $story['title'];
?></a></h3>
<?php echo fictioneer_get_card_controls( $post->ID ); ?>
<?php echo fictioneer_get_card_controls( $post_id ); ?>
</div>

View File

@ -123,15 +123,16 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$post_id = $post->ID;
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
if ( get_post_status( $story_id ) !== 'publish' ) {
continue;
}
$title = fictioneer_get_safe_title( $post->ID, 'shortcode-latest-chapters-compact' );
$title = fictioneer_get_safe_title( $post_id, 'shortcode-latest-chapters-compact' );
$story = $story_id ? fictioneer_get_story_data( $story_id, false ) : null; // Does not refresh comment count!
$text_icon = get_post_meta( $post->ID, 'fictioneer_chapter_text_icon', true );
$text_icon = get_post_meta( $post_id, 'fictioneer_chapter_text_icon', true );
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
$card_classes = [];
@ -173,7 +174,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card watch-last-clicked _small _info _chapter _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card watch-last-clicked _small _info _chapter _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<button class="card__info-toggle toggle-last-clicked" aria-label="<?php esc_attr_e( 'Open info box', 'fictioneer' ); ?>"><i class="fa-solid fa-chevron-down"></i></button>
@ -186,7 +187,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $title,
'classes' => 'card__image cell-img',
'permalink' => get_permalink(),
@ -201,7 +202,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
?>
<h3 class="card__title _small cell-title"><a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php
$list_title = get_post_meta( $post->ID, 'fictioneer_chapter_list_title', true );
$list_title = get_post_meta( $post_id, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( ! empty( $post->post_password ) ) {
@ -235,7 +236,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
printf(
_x( '%1$s Words on %2$s', 'Small card: {n} Words on {Date}.', 'fictioneer' ),
fictioneer_shorten_number( fictioneer_get_word_count( $post->ID ) ),
fictioneer_shorten_number( fictioneer_get_word_count( $post_id ) ),
get_the_time( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE )
);
?>

View File

@ -124,16 +124,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$post_id = $post->ID;
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
if ( get_post_status( $story_id ) !== 'publish' ) {
continue;
}
$title = fictioneer_get_safe_title( $post->ID, 'shortcode-latest-chapters' );
$chapter_rating = get_post_meta( $post->ID, 'fictioneer_chapter_rating', true );
$title = fictioneer_get_safe_title( $post_id, 'shortcode-latest-chapters' );
$chapter_rating = get_post_meta( $post_id, 'fictioneer_chapter_rating', true );
$story = $story_id ? fictioneer_get_story_data( $story_id, false ) : null; // Does not refresh comment count!
$text_icon = get_post_meta( $post->ID, 'fictioneer_chapter_text_icon', true );
$text_icon = get_post_meta( $post_id, 'fictioneer_chapter_text_icon', true );
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
$card_classes = [];
@ -182,7 +183,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card _small _chapter <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card _small _chapter <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main <?php echo $grid_or_vertical; ?> _small">
@ -193,7 +194,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $title,
'classes' => 'card__image cell-img',
'permalink' => get_permalink(),
@ -208,7 +209,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
?>
<h3 class="card__title _small cell-title"><a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php
$list_title = get_post_meta( $post->ID, 'fictioneer_chapter_list_title', true );
$list_title = get_post_meta( $post_id, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( ! empty( $post->post_password ) ) {
@ -270,7 +271,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
$footer_items['words'] = '<i class="card-footer-icon fa-solid fa-font" title="' .
esc_attr__( 'Words', 'fictioneer' ) . '"></i> ' .
fictioneer_shorten_number( fictioneer_get_word_count( $post->ID ) );
fictioneer_shorten_number( fictioneer_get_word_count( $post_id ) );
if ( $args['orderby'] == 'modified' ) {
$footer_items['modified_date'] = '<i class="card-footer-icon fa-regular fa-clock" title="' .

View File

@ -102,8 +102,9 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'shortcode-latest-recommendations-compact' );
$one_sentence = get_post_meta( $post->ID, 'fictioneer_recommendation_one_sentence', true );
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'shortcode-latest-recommendations-compact' );
$one_sentence = get_post_meta( $post_id, 'fictioneer_recommendation_one_sentence', true );
$fandoms = get_the_terms( $post, 'fcn_fandom' );
$characters = get_the_terms( $post, 'fcn_character' );
$genres = get_the_terms( $post, 'fcn_genre' );
@ -147,7 +148,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card watch-last-clicked _small _recommendation _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card watch-last-clicked _small _recommendation _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<?php if ( $show_taxonomies ) : ?>
@ -162,7 +163,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $title,
'classes' => 'card__image cell-img',
'permalink' => get_permalink(),
@ -182,7 +183,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<span class="card__by-author"><?php
printf(
_x( 'by %s —', 'Small card: by {Author} —.', 'fictioneer' ),
'<span class="author">' . get_post_meta( $post->ID, 'fictioneer_recommendation_author', true ) . '</span>'
'<span class="author">' . get_post_meta( $post_id, 'fictioneer_recommendation_author', true ) . '</span>'
);
?></span>
<span><?php

View File

@ -103,8 +103,9 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'shortcode-latest-recommendations' );
$one_sentence = get_post_meta( $post->ID, 'fictioneer_recommendation_one_sentence', true );
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'shortcode-latest-recommendations' );
$one_sentence = get_post_meta( $post_id, 'fictioneer_recommendation_one_sentence', true );
$fandoms = get_the_terms( $post, 'fcn_fandom' );
$characters = get_the_terms( $post, 'fcn_character' );
$genres = get_the_terms( $post, 'fcn_genre' );
@ -130,8 +131,8 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
// Sources
$urls = array_merge(
explode( "\n", get_post_meta( $post->ID, 'fictioneer_recommendation_urls', true ) ),
explode( "\n", get_post_meta( $post->ID, 'fictioneer_recommendation_support', true ) )
explode( "\n", get_post_meta( $post_id, 'fictioneer_recommendation_urls', true ) ),
explode( "\n", get_post_meta( $post_id, 'fictioneer_recommendation_support', true ) )
);
// Sanitize
@ -166,7 +167,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card _small _recommendation _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card _small _recommendation _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main <?php echo $grid_or_vertical; ?> _small">
@ -177,7 +178,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $title,
'classes' => 'card__image cell-img',
'permalink' => get_permalink(),
@ -196,7 +197,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<span class="card__by-author"><?php
printf(
_x( 'by %s on', 'Small card: by {Author} on.', 'fictioneer' ),
'<span class="author">' . get_post_meta( $post->ID, 'fictioneer_recommendation_author', true ) . '</span>'
'<span class="author">' . get_post_meta( $post_id, 'fictioneer_recommendation_author', true ) . '</span>'
);
?></span>
<a href="<?php echo esc_url( $tuple[1] ); ?>" rel="noopener" target="_blank" class="bold-link"><?php

View File

@ -121,10 +121,11 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post->ID );
$post_id = $post->ID;
$story = fictioneer_get_story_data( $post_id, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post_id, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post_id );
$tags = get_option( 'fictioneer_show_tags_on_story_cards' ) ? get_the_tags( $post ) : false;
$is_sticky = FICTIONEER_ENABLE_STICKY_CARDS && get_post_meta( $post->ID, 'fictioneer_story_sticky', true );
$is_sticky = FICTIONEER_ENABLE_STICKY_CARDS && get_post_meta( $post_id, 'fictioneer_story_sticky', true );
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
$card_classes = [];
@ -172,7 +173,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card watch-last-clicked _small _story _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card watch-last-clicked _small _story _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<?php if ( $show_taxonomies ) : ?>
@ -187,7 +188,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $story['title'],
'classes' => 'card__image cell-img',
'permalink' => $story_link,
@ -217,7 +218,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php endif; ?>
<span><?php
$short_description = fictioneer_first_paragraph_as_excerpt(
fictioneer_get_content_field( 'fictioneer_story_short_description', $post->ID )
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
);
echo strlen( $short_description ) < 230 ? get_the_excerpt() : $short_description;
?></span>

View File

@ -118,10 +118,11 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post->ID );
$post_id = $post->ID;
$story = fictioneer_get_story_data( $post_id, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post_id, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post_id );
$tags = get_option( 'fictioneer_show_tags_on_story_cards' ) ? get_the_tags( $post ) : false;
$is_sticky = FICTIONEER_ENABLE_STICKY_CARDS && get_post_meta( $post->ID, 'fictioneer_story_sticky', true );
$is_sticky = FICTIONEER_ENABLE_STICKY_CARDS && get_post_meta( $post_id, 'fictioneer_story_sticky', true );
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
$card_classes = [];
@ -164,7 +165,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card _small _story <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card _small _story <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main <?php echo $grid_or_vertical; ?> _small">
@ -175,7 +176,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $story['title'],
'classes' => 'card__image cell-img',
'permalink' => $story_link,
@ -205,7 +206,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php endif; ?>
<span><?php
$short_description = fictioneer_first_paragraph_as_excerpt(
fictioneer_get_content_field( 'fictioneer_story_short_description', $post->ID )
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
);
echo strlen( $short_description ) < 230 ? get_the_excerpt() : $short_description;
?></span>

View File

@ -129,8 +129,9 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post->ID );
$post_id = $post->ID;
$story = fictioneer_get_story_data( $post_id, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post_id, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post_id );
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
$chapter_list = [];
$chapter_excerpt; // Set inside inner loop
@ -202,7 +203,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card watch-last-clicked _small _info _story-update _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card watch-last-clicked _small _info _story-update _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<button class="card__info-toggle toggle-last-clicked" aria-label="<?php esc_attr_e( 'Open info box', 'fictioneer' ); ?>"><i class="fa-solid fa-chevron-down"></i></button>
@ -215,7 +216,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $story['title'],
'classes' => 'card__image cell-img',
'permalink' => $story_link,
@ -245,7 +246,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php endif; ?>
<span><?php
$short_description = fictioneer_first_paragraph_as_excerpt(
fictioneer_get_content_field( 'fictioneer_story_short_description', $post->ID )
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
);
echo strlen( $short_description ) < 230 ? get_the_excerpt() : $short_description;
?></span>

View File

@ -130,8 +130,9 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php
// Setup
$story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post->ID );
$post_id = $post->ID;
$story = fictioneer_get_story_data( $post_id, false ); // Does not refresh comment count!
$story_link = get_post_meta( $post_id, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $post_id );
$tags = get_option( 'fictioneer_show_tags_on_story_cards' ) ? get_the_tags( $post ) : false;
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
$chapter_list = [];
@ -215,7 +216,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
?>
<li class="post-<?php echo $post->ID; ?> card _small _story-update <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<li class="post-<?php echo $post_id; ?> card _small _story-update <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
<div class="card__body polygon">
<div class="card__main <?php echo $grid_or_vertical; ?> _small">
@ -226,7 +227,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
if ( $args['thumbnail'] ) {
fictioneer_output_small_card_thumbnail(
array(
'post_id' => $post->ID,
'post_id' => $post_id,
'title' => $story['title'],
'classes' => 'card__image cell-img',
'permalink' => $story_link,
@ -256,7 +257,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<?php endif; ?>
<span><?php
$short_description = fictioneer_first_paragraph_as_excerpt(
fictioneer_get_content_field( 'fictioneer_story_short_description', $post->ID )
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
);
echo strlen( $short_description ) < 230 ? get_the_excerpt() : $short_description;
?></span>

View File

@ -99,18 +99,19 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
<figure class="showcase__list-item-figure">
<?php
// Setup
$post_id = $post->ID;
$list_title = '';
$story_id = null;
$landscape_image_id = get_post_meta( $post->ID, 'fictioneer_landscape_image', true );
$landscape_image_id = get_post_meta( $post_id, 'fictioneer_landscape_image', true );
// Get list title and story ID (if any)
switch ( $args['post_type'] ) {
case 'fcn_collection':
$list_title = get_post_meta( $post->ID, 'fictioneer_collection_list_title', true );
$list_title = get_post_meta( $post_id, 'fictioneer_collection_list_title', true );
break;
case 'fcn_chapter':
$list_title = get_post_meta( $post->ID, 'fictioneer_chapter_list_title', true );
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$list_title = get_post_meta( $post_id, 'fictioneer_chapter_list_title', true );
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
if ( empty( $landscape_image_id ) ) {
$landscape_image_id = get_post_meta( $story_id, 'fictioneer_landscape_image', true );
@ -121,7 +122,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
// Prepare titles
$list_title = trim( wp_strip_all_tags( $list_title ) );
$title = empty( $list_title ) ? fictioneer_get_safe_title( $post->ID, 'shortcode-showcase' ) : $list_title;
$title = empty( $list_title ) ? fictioneer_get_safe_title( $post_id, 'shortcode-showcase' ) : $list_title;
// Prepare image arguments
$image_args = array(

View File

@ -147,6 +147,7 @@ do_action( 'rss_tag_pre', 'rss2' );
foreach ( $chapter_query->posts as $post ) {
// Setup
setup_postdata( $post );
$post_id = $post->ID;
// Terminate?
if ( $terminator < 1 ) {
@ -154,7 +155,7 @@ do_action( 'rss_tag_pre', 'rss2' );
}
// Skip invisible chapters
if ( get_post_meta( $post->ID, 'fictioneer_chapter_hidden', true ) ) {
if ( get_post_meta( $post_id, 'fictioneer_chapter_hidden', true ) ) {
continue;
}
@ -163,7 +164,7 @@ do_action( 'rss_tag_pre', 'rss2' );
// Data
$pub_date = mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false );
$og_image = fictioneer_get_seo_image( $post->ID );
$og_image = fictioneer_get_seo_image( $post_id );
// <-- Start HTML
?>
@ -184,25 +185,25 @@ do_action( 'rss_tag_pre', 'rss2' );
<?php endif; ?>
<?php
if ( $chapter_fandoms = get_the_terms( $post->ID, 'fcn_fandom' ) ) {
if ( $chapter_fandoms = get_the_terms( $post_id, 'fcn_fandom' ) ) {
foreach ( $chapter_fandoms as $fandom ) {
echo '<category>' . $fandom->name . '</category>';
}
}
if ( $chapter_genres = get_the_terms( $post->ID, 'fcn_genre' ) ) {
if ( $chapter_genres = get_the_terms( $post_id, 'fcn_genre' ) ) {
foreach ( $chapter_genres as $genre ) {
echo '<category>' . $genre->name . '</category>';
}
}
if ( $chapter_characters = get_the_terms( $post->ID, 'fcn_character' ) ) {
if ( $chapter_characters = get_the_terms( $post_id, 'fcn_character' ) ) {
foreach ( $chapter_characters as $character ) {
echo '<category>' . $character->name . '</category>';
}
}
if ( $chapter_tags = get_the_tags( $post->ID ) ) {
if ( $chapter_tags = get_the_tags( $post_id ) ) {
foreach ( $chapter_tags as $tag ) {
echo '<category>' . $tag->name . '</category>';
}