edited ajuts search
This commit is contained in:
parent
f9efa78efc
commit
6e1a0f6ef0
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* The template for displaying archive custom post type ajut
|
||||
*
|
||||
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
|
||||
*
|
||||
* @package Xarxaprod_theme
|
||||
*/
|
||||
|
||||
get_header();
|
||||
?>
|
||||
|
||||
<main id="primary" class="site-main">
|
||||
|
||||
<section id="filteredfunds" class="xarxaprod-filtered-funds xarxaprod-ajuts-filtrats">
|
||||
|
||||
<aside id="fundsfilter" class="xarxaprod-filter-funds xarxaprod-fitre-ajuts">
|
||||
|
||||
<div id="arhive-filters" class="xarxaprod-filters">
|
||||
<?php
|
||||
// output all possible values of a checkbox
|
||||
$groupkey = "group_63ab636898703"; // write here the key for the group of fields from acf
|
||||
if( $groupkey){
|
||||
//echo '<h6>check the groupkey <span style="color: #00b">' . $groupkey . '</span></h6>';
|
||||
$groupkey_fields = acf_get_fields($groupkey);
|
||||
foreach( $groupkey_fields as $field_key ) {
|
||||
if( $field_key['type'] == 'checkbox' ){
|
||||
//echo '<span style="color: #00b">' . ($field_key['key']) . '</span><br/>';
|
||||
//echo '<span style="color: #00b">' . ($field_key['label']) . '</span><br/>';
|
||||
//echo '<span style="color: #00b">' . ($field_key['name']) . '</span><br/>';
|
||||
// https://wordpress.stackexchange.com/a/102915
|
||||
//$field_key = "field_XXXXXX";// the acf field key unic numbers
|
||||
$field_key = $field_key['key'];
|
||||
$fields = get_field_object($field_key);
|
||||
|
||||
if( $fields )
|
||||
{
|
||||
// check for values in url
|
||||
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ):
|
||||
|
||||
// set value if available
|
||||
if( isset($_GET[ $fieldname ]) ) {
|
||||
|
||||
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
||||
|
||||
};
|
||||
|
||||
// construct the checkboxes
|
||||
if( $fieldname == $fields['name']) {
|
||||
echo '<nav id="fund-filter" class="xarxaprod-filter ' . $fields['name'] . '">' ;
|
||||
echo '<h5>' . $fields['label'] . '</h5>';
|
||||
echo '<ul>';
|
||||
|
||||
foreach( $fields['choices'] as $choicevalue => $choicelabel ) {
|
||||
echo '<li>';
|
||||
echo '<input type="checkbox" ';
|
||||
echo ' value="' . $choicevalue . '" ';
|
||||
if( in_array($choicevalue,$filteredvalues['value']) ):
|
||||
echo ' checked="checked" ';
|
||||
endif;
|
||||
echo ' />';
|
||||
echo $choicelabel;
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</nav>';
|
||||
};
|
||||
// end of construct checkboxes
|
||||
|
||||
endforeach;
|
||||
// end check for values in url
|
||||
}
|
||||
};//end if type checkbox
|
||||
};//end foreach groupkey field
|
||||
};//end if groupkey
|
||||
?>
|
||||
|
||||
<?php //endforeach; ?>
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
<content class="archive-posts <?php xarxaprod_class_posttype(); ?>">
|
||||
|
||||
<?php if ( have_posts() ) : ?>
|
||||
<?php while ( have_posts() ) : the_post();
|
||||
|
||||
get_template_part( 'template-parts/section', 'eachpost' );
|
||||
|
||||
endwhile;
|
||||
|
||||
|
||||
else :
|
||||
|
||||
get_template_part( 'template-parts/content', 'none' );
|
||||
|
||||
endif;
|
||||
?>
|
||||
|
||||
</content>
|
||||
</section>
|
||||
|
||||
</main><!-- #main -->
|
||||
|
||||
<?php
|
||||
get_footer();
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* The template for displaying archive custom post type xarxaprod-ajut
|
||||
*
|
||||
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
|
||||
*
|
||||
* @package Xarxaprod_theme
|
||||
*/
|
||||
|
||||
get_header();
|
||||
?>
|
||||
|
||||
<main id="primary" class="site-main">
|
||||
<?php
|
||||
// Detect plugin. For use on Front End only.
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
// check for plugin using plugin name
|
||||
if ( is_plugin_active( 'xarxaprod-wp-plugin/xarxaprod-wp-plugin.php' ) ) {
|
||||
//plugin is activated do
|
||||
?>
|
||||
|
||||
<section id="filteredfunds" class="xarxaprod-filtered-funds xarxaprod-ajuts-filtrats">
|
||||
<aside id="fundsfilter" class="xarxaprod-filter-funds xarxaprod-filtre-ajuts">
|
||||
|
||||
<script type="text/javascript">
|
||||
<!-- https://stackoverflow.com/a/48314274 -->
|
||||
(function($) {
|
||||
$('.fund-filter').ready(function() {
|
||||
$('.xarxaprod-titol-opcions').click(function() {
|
||||
$(this).siblings(".filter").toggle();
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
||||
<?php xarxaprod_ajuts_filters_form(); // function defined in the plugin ?>
|
||||
|
||||
</aside>
|
||||
|
||||
<content class="archive-posts <?php xarxaprod_class_posttype(); ?>">
|
||||
|
||||
<?php if ( have_posts() ) : ?>
|
||||
<?php while ( have_posts() ) : the_post();
|
||||
|
||||
get_template_part( 'template-parts/section', 'eachpost' );
|
||||
|
||||
endwhile;
|
||||
|
||||
the_posts_navigation();
|
||||
|
||||
else :
|
||||
|
||||
get_template_part( 'template-parts/content', 'none' );
|
||||
|
||||
endif;
|
||||
?>
|
||||
|
||||
</content>
|
||||
</section>
|
||||
|
||||
<?php } //end plugin is activated do ?>
|
||||
</main><!-- #main -->
|
||||
|
||||
<?php
|
||||
get_footer();
|
|
@ -182,8 +182,3 @@ require get_template_directory() . '/inc/archive-title.php';
|
|||
*/
|
||||
require get_template_directory() . '/inc/admin-style.php';
|
||||
|
||||
/**
|
||||
* Function to add filter in xarxaprod-ajut custom post
|
||||
*/
|
||||
// moved to plugin on 2023 01 05
|
||||
//require get_template_directory() . '/inc/xarxaprod-ajut-filter.php';
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Makes a filter for the custom post type ajut and its custom fields
|
||||
*/
|
||||
|
||||
// action
|
||||
add_action('pre_get_posts', 'my_pre_get_posts');
|
||||
|
||||
function my_pre_get_posts( $query ) {
|
||||
|
||||
// bail early if is in admin
|
||||
if( is_admin() ) { return; }
|
||||
|
||||
|
||||
// allow the url to alter the query
|
||||
if( isset($_GET['os_fund_target']) )
|
||||
{
|
||||
// get original meta query
|
||||
$meta_query = [];
|
||||
$meta_query[] = array('relation' => 'OR');
|
||||
$meta_query[] = $query->get('meta_query');
|
||||
$fieldsearchvalues= explode(',', $_GET['os_fund_target']);
|
||||
foreach( $fieldsearchvalues as $fieldsearchvalue ){
|
||||
$os_search_value = $fieldsearchvalue; //'entitat-publica'; // whatever
|
||||
$os_field_value = sprintf( '^%1$s$|s:%2$u:"%1$s";', $os_search_value, strlen( $os_search_value ) );
|
||||
|
||||
// add aur meta query to the original meta queries
|
||||
$meta_query[] = array(
|
||||
array(
|
||||
'key' => 'os_fund_target',
|
||||
'value' => $os_field_value,
|
||||
'compare' => 'REGEXP',
|
||||
),
|
||||
);
|
||||
}
|
||||
// update the meta query arguments
|
||||
$query->set('meta_query', $meta_query);
|
||||
}
|
||||
|
||||
//always return
|
||||
return;
|
||||
}
|
|
@ -63,3 +63,72 @@ function xarxaprod_class_posttype (){
|
|||
printf(get_post_type_object( get_post_type() )->rewrite['slug'] );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Displays the FAQS subcategories from category id=1
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'ofisuport_display_faqs_labels' ) ) :
|
||||
function ofisuport_display_faqs_labels() {
|
||||
?>
|
||||
<nav id="tipus-faqs" class="ofisuport-faqs-types">
|
||||
<ul class="ofisuport-label">
|
||||
<?php
|
||||
// https://developer.wordpress.org/reference%2Ffunctions%2Fwp_list_categories%2F/
|
||||
wp_list_categories(
|
||||
array(
|
||||
'child_of' => 1, // category FAQ id=1
|
||||
'hide_empty' => 1,
|
||||
'hide_title_if_empty' => true,
|
||||
'separator' => '<li>',
|
||||
'style' => 'list',
|
||||
'taxonomy' => 'category',
|
||||
'title_li' => '',
|
||||
)
|
||||
); ?>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php
|
||||
}
|
||||
endif; //end ofisuport_display_faqs_labels
|
||||
/**
|
||||
* Displays categories for each FAQ
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'ofisuport_display_each_faq_categories' ) ) :
|
||||
function ofisuport_display_each_faq_categories() {
|
||||
|
||||
$categories = get_the_category();
|
||||
if ( ! empty( $categories ) ) {
|
||||
echo ' <nav id="tipus-faqs" class="ofisuport-faqs-types">';
|
||||
echo ' <ul class="ofisuport-label">';
|
||||
foreach ( $categories as $category ) {
|
||||
if ( ! ($category->cat_ID == '1') ) { //cat_ID '1' is defined as default FAQ
|
||||
echo '<li class="cat-item"><a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a></li>';
|
||||
}
|
||||
}
|
||||
echo ' </ul>';
|
||||
echo ' </nav>';
|
||||
}
|
||||
}
|
||||
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
|
||||
?>
|
||||
<form class="ofisuport-search-form" role="search" method="get" action="/">
|
||||
<label class="screen-reader-text" for="search">Search in ajuts</label>
|
||||
<input type="search" id="search" class="search-field" placeholder="cerca faqs..." value="<?php the_search_query();?>" name="s" />
|
||||
<input type="submit" id="searchsubmit" class="search-submit button button-search" value="cerca">
|
||||
<span class="ofisuport-search-submit ofisuport-icon-search"></span>
|
||||
<input type="hidden" value="posts" name="post_type" id="post_type" />
|
||||
<input type="hidden" value="faq" name="category_name" id="category_name" />
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
endif; //end ofisuport_display_each_faq_categories
|
||||
|
|
|
@ -39,52 +39,47 @@ get_header();
|
|||
|
||||
<aside id="fundsfilter" class="xarxaprod-filter-funds xarxaprod-fitre-ajuts">
|
||||
<?php include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( is_plugin_active( 'xarxaprod-wp-plugin/xarxaprod-wp-plugin.php' ) ) { // if plugin active do?>
|
||||
<nav class="sidebar fund-filter">
|
||||
|
||||
</nav>
|
||||
<script type="text/javascript">
|
||||
<!-- https://stackoverflow.com/a/48314274 -->
|
||||
(function($) {
|
||||
$('.fund-filter').ready(function() {
|
||||
$('.xarxaprod-titol-opcions').click(function() {
|
||||
$(this).siblings(".filter").toggle();
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
||||
<?php xarxaprod_ajuts_filters_form(); // function defined in the plugin ?>
|
||||
|
||||
<?php } //end if is_plugin_active ?>
|
||||
|
||||
|
||||
</aside>
|
||||
|
||||
|
||||
<content class="archive-posts <?php xarxaprod_class_posttype(); ?>">
|
||||
|
||||
<content class="archive-posts <?php xarxaprod_class_posttype(); ?>">
|
||||
|
||||
<?php
|
||||
// https://support.advancedcustomfields.com/forums/topic/wp_query-using-meta_query-for-an-acf-checkbox-field/#post-145830
|
||||
// https://www.advancedcustomfields.com/resources/checkbox/#query-posts
|
||||
// https://barn2.com/blog/querying-posts-by-custom-field-acfi/
|
||||
// https://support.advancedcustomfields.com/forums/topic/wp_query-using-meta_query-for-an-acf-checkbox-field/#post-145830
|
||||
// https://www.advancedcustomfields.com/resources/checkbox/#query-posts
|
||||
// https://barn2.com/blog/querying-posts-by-custom-field-acfi/
|
||||
|
||||
$the_query_ajut = new WP_Query(
|
||||
array(
|
||||
'post_type' => 'xarxaprod-ajut',
|
||||
'post_per_page' => '6'
|
||||
)
|
||||
);
|
||||
?>
|
||||
<?php if ( $the_query_ajut->have_posts() ) : ?>
|
||||
<?php while ( $the_query_ajut->have_posts() ) : $the_query_ajut->the_post(); ?>
|
||||
$the_query_ajut = new WP_Query(
|
||||
array(
|
||||
'post_type' => 'xarxaprod-ajut',
|
||||
'posts_per_page' => '-1'
|
||||
)
|
||||
);
|
||||
?>
|
||||
<?php if ( $the_query_ajut->have_posts() ) : ?>
|
||||
<?php while ( $the_query_ajut->have_posts() ) : $the_query_ajut->the_post(); ?>
|
||||
|
||||
<?php get_template_part( 'template-parts/section', 'eachpost' ); ?>
|
||||
<?php get_template_part( 'template-parts/section', 'eachpost' ); ?>
|
||||
|
||||
<?php
|
||||
//the_title('<h3>','</h3>');
|
||||
// echo '<ul>';
|
||||
//$postmetas = get_post_meta(get_the_ID());
|
||||
// foreach($postmetas as $meta_key=>$meta_value) {
|
||||
// echo '<li><code>' . $meta_key . '</code>:<code>' . $meta_value[0] . '</code></li>';
|
||||
// } ;
|
||||
// echo '</ul>';
|
||||
?>
|
||||
<?php endwhile;//end of the loop ?>
|
||||
<?php wp_reset_postdata(); ?>
|
||||
<?php endif; //end query ajut ?>
|
||||
|
||||
|
||||
<?php endwhile;//end of the loop ?>
|
||||
<?php wp_reset_postdata(); ?>
|
||||
<?php endif; //end query ajut ?>
|
||||
|
||||
</content>
|
||||
</content>
|
||||
</section>
|
||||
|
||||
</main><!-- #main -->
|
||||
|
|
Loading…
Reference in New Issue