-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
search.php
173 lines (139 loc) · 5.66 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Search results
*
* @package WordPress
* @subpackage Fictioneer
* @since 5.0.0
* @since 5.11.0 - Consider querying for story status.
*/
global $wp_query;
// Setup
$count = $wp_query->found_posts;
$no_params = empty( array_filter( $_GET ) );
$post_type = sanitize_text_field( $_GET['post_type'] ?? 'any' );
$sentence = sanitize_text_field( $_GET['sentence'] ?? 0 );
$order = sanitize_text_field( $_GET['order'] ?? 'desc' );
$orderby = sanitize_text_field( $_GET['orderby'] ?? 'modified' );
$story_status = fictioneer_sanitize_query_var(
$_GET['story_status'] ?? 0,
['Completed', 'Ongoing', 'Oneshot', 'Hiatus', 'Canceled'],
0
);
$queried_genres = sanitize_text_field( $_GET['genres'] ?? 0 );
$queried_fandoms = sanitize_text_field( $_GET['fandoms'] ?? 0 );
$queried_characters = sanitize_text_field( $_GET['characters'] ?? 0 );
$queried_warnings = sanitize_text_field( $_GET['warnings'] ?? 0 );
$queried_tags = sanitize_text_field( $_GET['tags'] ?? 0 );
$queried_ex_genres = sanitize_text_field( $_GET['ex_genres'] ?? 0 );
$queried_ex_fandoms = sanitize_text_field( $_GET['ex_fandoms'] ?? 0 );
$queried_ex_characters = sanitize_text_field( $_GET['ex_characters'] ?? 0 );
$queried_ex_warnings = sanitize_text_field( $_GET['ex_warnings'] ?? 0 );
$queried_ex_tags = sanitize_text_field( $_GET['ex_tags'] ?? 0 );
// Prepare hook arguments
$hook_args = array(
'post_type' => $post_type,
'sentence' => $sentence,
'order' => $order,
'orderby' => $orderby,
'story_status' => $story_status,
'queried_genres' => $queried_genres,
'queried_fandoms' => $queried_fandoms,
'queried_characters' => $queried_characters,
'queried_warnings' => $queried_warnings,
'queried_tags' => $queried_tags,
'queried_ex_genres' => $queried_ex_genres,
'queried_ex_fandoms' => $queried_ex_fandoms,
'queried_ex_characters' => $queried_ex_characters,
'queried_ex_warnings' => $queried_ex_warnings,
'queried_ex_tags' => $queried_ex_tags
);
// Advanced search?
$is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified' || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings || $story_status;
$hook_args['is_advanced_search'] = $is_advanced_search;
// Header
get_header();
?>
<main id="main" class="main search-results">
<?php do_action( 'fictioneer_main', 'search' ); ?>
<div class="main__wrapper">
<?php do_action( 'fictioneer_main_wrapper' ); ?>
<article id="search-results" class="search-results__article">
<header class="search-results__header">
<h1 class="search-results__title">
<?php
if ( $is_advanced_search || ! empty( trim( get_search_query() ) ) ) {
$title_html = sprintf(
_n(
'<span class="search-results__number">%s</span> Search Result',
'<span class="search-results__number">%s</span> Search Results',
$count,
'fictioneer'
),
$count
);
} else {
$title_html = __( 'Search', 'fictioneer' );
}
// Apply filters
$title_html = apply_filters( 'fictioneer_filter_search_title', $title_html, $hook_args );
// Output
echo $title_html;
?>
</h1>
</header>
<?php
// Output search form ('pre_get_search_form' action fires here)
get_search_form( apply_filters( 'fictioneer_filter_default_search_form_args', [] ) );
// Actions after search form
do_action( 'fictioneer_search_form_after' );
?>
<?php if ( have_posts() && ! $no_params ) : ?>
<section class="search-results__content container-inline-size">
<ul id="search-result-list" class="scroll-margin-top card-list _no-mutation-observer">
<?php
while ( have_posts() ) {
the_post();
// Setup
$card_args = array( 'show_type' => true );
// Cached?
if ( fictioneer_caching_active( 'card_args' ) && ! fictioneer_private_caching_active() ) {
$card_args['cache'] = true;
}
// Echo correct card
fictioneer_echo_card( $card_args );
}
// Pagination
$pag_args = array(
'prev_text' => fcntr( 'previous' ),
'next_text' => fcntr( 'next' ),
'add_fragment' => '#search-result-list'
);
?>
</ul>
<nav class="pagination _padding-top"><?php echo fictioneer_paginate_links( $pag_args ); ?></nav>
</section>
<?php elseif ( $no_params ) : ?>
<section class="search-results__content _no-params container-inline-size"><?php do_action( 'fictioneer_search_no_params' ); ?></section>
<?php else : ?>
<section class="search-results__content _no-results container-inline-size"><?php do_action( 'fictioneer_search_no_results' ); ?></section>
<?php endif; ?>
<footer class="search-results__footer"><?php do_action( 'fictioneer_search_footer' ); ?></footer>
</article>
</div>
<?php do_action( 'fictioneer_main_end', 'search' ); ?>
</main>
<?php
// Footer arguments
$footer_args = array(
'post_type' => null,
'post_id' => null,
'template' => 'search.php',
'breadcrumbs' => array(
[fcntr( 'frontpage' ), get_home_url()],
[__( 'Search Results', 'fictioneer' ), null]
)
);
// Get footer with breadcrumbs
get_footer( null, $footer_args );
?>