Community Forums › Forums › General Genesis Framework Discussions › Custom search.php template for Genesis Framework
Tagged: reloj control asistencia
- This topic has 1 reply, 2 voices, and was last updated 1 year, 8 months ago by rachelgomez123.
-
AuthorPosts
-
March 11, 2021 at 8:49 am #503420annahernandez99Participant
I have setup a custom search.php template within the Genesis Framework and I've created an array variable for specific post types:
$post_types = array('treatment','post', 'team_member' );
However, I need to edit which fields are pulled in for each of the arrays as two out of three are custom post types built with ACF Pro (one is the default WP posts).
Please find the most up to date code below. Ideally, I want to set the number of posts that appear for the three arrays ('treatment','post', 'team_member' ) and what fields are pulled in.
<?php
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );/* Remove the default loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'hs_do_search_loop' );
add_action( 'genesis_before_loop', 'genesis_do_search_title' );/**
* Echo the title with the search term.
*
* @since 1.9.0
*/
function genesis_do_search_title() {$title = sprintf( '%s %s', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
/**
* Outputs a custom loop
*
* @global mixed $paged current page number if paginated
* @return void
*/
function hs_do_search_loop() {
// create an array variable with specific post types in your desired order
$post_types = array('treatment','post', 'team_member' ); // other custom post type can be added.
echo '<div class="search-content">';
foreach ( $post_types as $post_type ) {
// get the search term entered by user
$s = isset( $_GET["s"] ) ? $_GET["s"] : "";
// accepts any wp_query args
$args = (array(
's' => $s,
'post_type' => $post_type,
'posts_per_page' => 4,
'order' => 'ASC'
));
switch ( $post_type ) {
case 'treatment':
$post_type_heading = 'Treatments';
break;case 'post':
$post_type_heading = 'Latest News';
break;case 'team_member':
$post_type_heading = 'Consultants';
break;
}
echo '<div class="post-type '. $post_type .'"><div class="post-type-heading">'. $post_type_heading . '</div>';
// force content limit.
add_filter( 'genesis_pre_get_option_content_archive_limit', 'sk_content_limit' );
// modify the Content Limit read more link.
add_filter( 'get_the_content_more_link', 'sp_read_more_link' );
// remove archive pagination.
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
// custom genesis loop with the above query parameters and hooks.
genesis_custom_loop( $args );
echo '</div>';
}
}
echo '</div>'; // .search-content
function sk_content_limit() {
return '150'; // number of characters.
}
function sp_read_more_link() {
return '... Read more';
}
function sk_show_excerpts() {
return 'excerpts';
}
genesis();May 17, 2023 at 12:31 am #507425rachelgomez123ParticipantTo customize the fields and number of posts for each post type in your custom search.php template within the Genesis Framework:
Define the post types, fields, and number of posts you want to display.
Modify the switch case statement to specify the ACF field names for each post type.
Update the $args array to include the desired fields and posts_per_page value.
Replace 'field_name_1', 'field_name_2', etc. with the actual ACF field names you want to retrieve.
Set the appropriate post type heading for each case.
Customize the code to fit your specific needs and requirements.
Save the modified search.php file and test the changes on your website.Regards,
Rachel Gomez
rachelgomez
-
AuthorPosts
- You must be logged in to reply to this topic.