Let's talk about
For example:
A page about a thing.
A list of things.
archive (or archives)
n. a collection of records.
In WordPress, detail pages = posts:
Custom post types:
WordPress's archive pages:
But wait...
Usually:
Our way:
acf_add_options_sub_page( array(
'page_title' => 'Book Archive Page Settings',
'menu_title' => 'Archive Page',
'menu_slug' => 'book-archive',
'parent_slug' => 'edit.php?post_type=book'
) );
<?php the_field( 'books_title', 'option' ); ?>
<?php the_field( 'books_description', 'option' ); ?>
Usually:
Our way:
function my_books_query( $query ) {
}
add_action( 'pre_get_posts', 'my_books_query' );
function my_books_query( $query ) {
if ( is_admin() || !$query->is_main_query() )
return;
if ( !is_post_type_archive( 'book' ) )
return;
}
add_action( 'pre_get_posts', 'my_books_query' );
function my_books_query( $query ) {
if ( is_admin() || !$query->is_main_query() )
return;
if ( !is_post_type_archive( 'book' ) )
return;
$query->set( 'order', 'ASC' );
$query->set( 'orderby', 'title' );
$query->set( 'posts_per_page', '25' );
}
add_action( 'pre_get_posts', 'my_books_query' );
$query->set( 'posts_per_page',
get_field( 'books_per_page', 'option' ) );
<form method="get" action="/wp-content/plugins/raiders/slides/<?php echo esc_url( get_post_type_archive_link( 'book' ) ); ?>">
Filter by:
<?php wp_dropdown_categories( array(
'taxonomy' => 'genre',
'name' => 'book_genre',
'show_option_all' => 'Genre',
'selected' => (int) $_GET['book_genre'],
) ); ?>
</form>
In your hook function:
$genre = isset( $_GET['book_genre'] )
? (int) $_GET['book_genre'] : '';
if ( $genre ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => 'genre',
'terms' => $genre,
)
) );
}
$keyword = isset( $_GET['book_keyword'] )
? sanitize_text_field( $_GET['book_keyword'] ) : '';
if ( $keyword ) {
$query->set( 's', $keyword );
}