working logic for the search. different if is custom-post ofisuport-ajut or post category faq or else

This commit is contained in:
jorge 2023-04-07 19:35:23 +02:00
parent 0b3ddb4a5c
commit a8a2c55bc7
4 changed files with 63 additions and 7 deletions

View File

@ -112,3 +112,25 @@ if ( ! function_exists( 'ofisuport_display_each_faq_categories' ) ) :
} }
} }
endif; //end ofisuport_display_each_faq_categories endif; //end ofisuport_display_each_faq_categories
/**
* Display search form for FAQs
*/
if ( ! function_exists( 'ofisuport_display_faq_search' ) ) :
function ofisuport_display_faqs_search() {
// search form for category
// https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
// https://wordpress.stackexchange.com/questions/313037/restrict-a-search-to-a-custom-post-type
echo '<aside id="search-form-faqs" class="search-faqs">';
echo' <form class="search-form" role="search" method="get" action="/">';
echo' <label class="screen-reader-text" for="search">Search in ajuts</label>';
echo' <input type="search" id="search" class="search-field" placeholder="cerca faqs..." value="' . the_search_query() . '" name="s" />';
echo' <input type="submit" id="searchsubmit" class="search-submit button button-search" value="Enviar">';
echo' <input type="hidden" value="posts" name="post_type" id="post_type" />';
echo' <input type="hidden" value="faq" name="category_name" id="category_name" />';
echo' </form>';
echo'</aside>';
}
endif; //end ofisuport_display_each_faq_categories

View File

@ -44,6 +44,7 @@ get_header();
<?php //if( in_category('faq') ) : ?> <?php //if( in_category('faq') ) : ?>
<?php ofisuport_display_faqs_labels(); ?> <?php ofisuport_display_faqs_labels(); ?>
<?php ofisuport_display_faqs_search(); ?>
<?php //endif; //end if is_category faq ?> <?php //endif; //end if is_category faq ?>
<content class="archive-posts <?php ofisuport_class_posttype(); ?>"> <content class="archive-posts <?php ofisuport_class_posttype(); ?>">

View File

@ -15,14 +15,45 @@ get_header();
<?php if ( have_posts() ) : ?> <?php if ( have_posts() ) : ?>
<header class="page-header"> <header class="page-header">
<h1 class="page-title">
<?php
/* translators: %s: search query. */
printf( esc_html__( 'Search Results for: %s', 'ofisuport' ), '<span>' . get_search_query() . '</span>' );
?>
</h1>
</header><!-- .page-header --> </header><!-- .page-header -->
<?php
// check if is ofisuport-ajut
if ( get_post_type( get_the_ID() ) == 'ofisuport-ajut'){ ?>
<section id="filteredfunds" class="ofisuport-filtered-funds ofisuport-ajuts-filtrats">
<aside id="fundsfilter" class="ofisuport-filter-funds ofisuport-fitre-ajuts">
<script type="text/javascript">
<!-- https://stackoverflow.com/a/48314274 -->
(function($) {
$('.fund-filter').ready(function() {
$('.oficinasuport-titol-opcions').click(function() {
$(this).siblings(".filter").toggle();
});
});
})(jQuery);
</script>
<?php ofisuport_ajuts_filters_form(); // function defined in the plugin ?>
</aside>
<?php } elseif ( in_category ( 'faq' ) ) { ?>
<section id="filteredsearch" class="ofisuport-searched-query ofisuport-search-faqs">
<?php //if( in_category('faq') ) : ?>
<?php ofisuport_display_faqs_labels(); ?>
<?php ofisuport_display_faqs_search(); ?>
<?php //endif; //end if is_category faq ?>
<?php } else { ?>
<section id="filteredsearch" class="ofisuport-searched-query">
<?php
/* translators: %s: search query. */
printf( esc_html__( 'Search Results for: %s', 'ofisuport' ), '<br/><span class="h5 search-query">' . get_search_query() . '</span>' );
?>
<?php }; // end if is ofisuport-ajut ?>
<content class="archive-posts <?php ofisuport_class_posttype(); ?>">
<?php <?php
/* Start the Loop */ /* Start the Loop */
while ( have_posts() ) : while ( have_posts() ) :
@ -46,6 +77,8 @@ get_header();
endif; endif;
?> ?>
</content>
</section>
</main><!-- #main --> </main><!-- #main -->
<?php <?php

View File

@ -11,7 +11,7 @@
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header"> <header class="entry-header">
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?> <?php the_title( sprintf( '<h3 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' ); ?>
<?php if ( 'post' === get_post_type() ) : ?> <?php if ( 'post' === get_post_type() ) : ?>
<div class="entry-meta"> <div class="entry-meta">