Sticky stories query - final form (maybe)
This commit is contained in:
parent
2267ca8aba
commit
0577cc40f4
@ -907,7 +907,6 @@ Filters the query arguments in the `fictioneer_latest_stories` shortcode. The op
|
||||
* $fictioneer_story_sticky – `'DESC'`
|
||||
* `$args['orderby']` – `$args['order']`
|
||||
* $posts_per_page (int) – `$args['count']`
|
||||
* $meta_key (string) – `'fictioneer_story_sticky'`
|
||||
* $meta_query (array)
|
||||
* $relation (string) – `'OR'`
|
||||
* (array)
|
||||
@ -1142,7 +1141,6 @@ Filters the arguments to query the stories in the `stories.php` template.
|
||||
* $orderby (array) – `'modified'`, `'date'`, `'title'`, or `'rand'`
|
||||
* $paged (int) – Current page number or `1`.
|
||||
* $posts_per_page (int) – `get_option( 'posts_per_page' )`
|
||||
* $meta_key (string) – `'fictioneer_story_sticky'`
|
||||
* $meta_query (array)
|
||||
* $relation (string) – `'OR'`
|
||||
* (array)
|
||||
|
@ -39,6 +39,7 @@ $tabs = [];
|
||||
$tabs['stories'] = array(
|
||||
'name' => __( 'Stories', 'fictioneer' ),
|
||||
'query_args' => array(
|
||||
'fictioneer_query_name' => 'author_stories',
|
||||
'post_type' => 'fcn_story',
|
||||
'author' => $author_id,
|
||||
'orderby' => 'modified',
|
||||
@ -60,15 +61,11 @@ $tabs['stories'] = array(
|
||||
'empty' => __( 'No stories published yet.', 'fictioneer' )
|
||||
);
|
||||
|
||||
if ( FICTIONEER_ENABLE_STICKY_CARDS ) {
|
||||
$tabs['stories']['query_args']['meta_key'] = 'fictioneer_story_sticky';
|
||||
$tabs['stories']['query_args']['orderby'] = 'meta_value ' . $tabs['stories']['query_args']['orderby'];
|
||||
}
|
||||
|
||||
// Chapters tab
|
||||
$tabs['chapters'] = array(
|
||||
'name' => __( 'Chapters', 'fictioneer' ),
|
||||
'query_args' => array(
|
||||
'fictioneer_query_name' => 'author_chapters',
|
||||
'post_type' => 'fcn_chapter',
|
||||
'author' => $author_id,
|
||||
'paged' => $current_page,
|
||||
@ -94,6 +91,7 @@ if ( user_can( $author_id, 'publish_fcn_recommendations' ) ) {
|
||||
$tabs['recommendations'] = array(
|
||||
'name' => __( 'Recommendations', 'fictioneer' ),
|
||||
'query_args' => array(
|
||||
'fictioneer_query_name' => 'author_recommendations',
|
||||
'post_type' => 'fcn_recommendation',
|
||||
'author' => $author_id,
|
||||
'paged' => $current_page,
|
||||
|
@ -208,4 +208,37 @@ function fictioneer_exclude_protected_posts( $where = '' ) {
|
||||
return $where;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// STICKY STORIES
|
||||
// =============================================================================
|
||||
|
||||
function fictioneer_clause_sticky_stories( $clauses, $wp_query ) {
|
||||
global $wpdb;
|
||||
|
||||
// Setup
|
||||
$vars = $wp_query->query_vars;
|
||||
$allowed_queries = ['stories_list', 'latest_stories', 'latest_stories_compact', 'author_stories'];
|
||||
$allowed_orderby = ['date', 'modified', 'title'];
|
||||
|
||||
// Return if wrong query
|
||||
if (
|
||||
! in_array( $vars['fictioneer_query_name'] ?? 0 , $allowed_queries) ||
|
||||
! in_array( $vars['orderby'] ?? '', $allowed_orderby )
|
||||
) {
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
// Update clauses to set missing meta key to 0
|
||||
$clauses['join'] .= " LEFT JOIN $wpdb->postmeta AS m ON ($wpdb->posts.ID = m.post_id AND m.meta_key = 'fictioneer_story_sticky')";
|
||||
$clauses['orderby'] = "COALESCE(m.meta_value+0, 0) DESC, " . $clauses['orderby'];
|
||||
$clauses['groupby'] = "$wpdb->posts.ID";
|
||||
|
||||
// Pass to query
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
if ( FICTIONEER_ENABLE_STICKY_CARDS ) {
|
||||
add_filter( 'posts_clauses', 'fictioneer_clause_sticky_stories', 10, 2 );
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -55,15 +55,6 @@ $query_args = array(
|
||||
'no_found_rows' => true
|
||||
);
|
||||
|
||||
if ( FICTIONEER_ENABLE_STICKY_CARDS ) {
|
||||
$query_args['meta_key'] = 'fictioneer_story_sticky';
|
||||
|
||||
$query_args['orderby'] = array(
|
||||
'fictioneer_story_sticky' => 'DESC',
|
||||
$args['orderby'] => $args['order']
|
||||
);
|
||||
}
|
||||
|
||||
// Author?
|
||||
if ( ! empty( $args['author'] ) ) {
|
||||
$query_args['author_name'] = $args['author'];
|
||||
|
@ -52,15 +52,6 @@ $query_args = array(
|
||||
'no_found_rows' => true
|
||||
);
|
||||
|
||||
if ( FICTIONEER_ENABLE_STICKY_CARDS ) {
|
||||
$query_args['meta_key'] = 'fictioneer_story_sticky';
|
||||
|
||||
$query_args['orderby'] = array(
|
||||
'fictioneer_story_sticky' => 'DESC',
|
||||
$args['orderby'] => $args['order']
|
||||
);
|
||||
}
|
||||
|
||||
// Author?
|
||||
if ( ! empty( $args['author'] ) ) {
|
||||
$query_args['author_name'] = $args['author'];
|
||||
|
@ -41,6 +41,7 @@ get_header( null, array( 'type' => 'fcn_collection' ) );
|
||||
|
||||
// Prepare raw query (because meta query takes far too long)
|
||||
$raw_query_args = array (
|
||||
'fictioneer_query_name' => 'collection_featured_raw',
|
||||
'post_type' => 'any',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => fictioneer_rescue_array_zero( $featured_list ),
|
||||
@ -67,6 +68,7 @@ get_header( null, array( 'type' => 'fcn_collection' ) );
|
||||
|
||||
// Prepare paginated featured query
|
||||
$query_args = array (
|
||||
'fictioneer_query_name' => 'collection_featured',
|
||||
'post_type' => 'any',
|
||||
'post__in' => fictioneer_rescue_array_zero( $featured_list ),
|
||||
'ignore_sticky_posts' => 1,
|
||||
|
@ -46,15 +46,6 @@ $query_args = array (
|
||||
)
|
||||
);
|
||||
|
||||
if ( FICTIONEER_ENABLE_STICKY_CARDS ) {
|
||||
$query_args['meta_key'] = 'fictioneer_story_sticky';
|
||||
|
||||
$query_args['orderby'] = array(
|
||||
'fictioneer_story_sticky' => 'DESC',
|
||||
$orderby => $order
|
||||
);
|
||||
}
|
||||
|
||||
// Append date query (if any)
|
||||
$query_args = fictioneer_append_date_query( $query_args, $ago, $orderby );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user