Compare commits
No commits in common. "e6277a5e8965d2338e9959e3ab61a4d702f1ecbe" and "02d003934c70501972c656de689902a54f0162f5" have entirely different histories.
e6277a5e89
...
02d003934c
|
@ -17,7 +17,6 @@
|
||||||
/readme.html
|
/readme.html
|
||||||
/wp-*.php
|
/wp-*.php
|
||||||
/xmlrpc.php
|
/xmlrpc.php
|
||||||
/ignore-*
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
wp-config.php
|
wp-config.php
|
||||||
|
|
|
@ -15,3 +15,10 @@
|
||||||
* css styles
|
* css styles
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
.xarxaprod-filtered-funds .os_fund_target .filter,
|
||||||
|
.xarxaprod-filtered-funds .os_fund_source .filter,
|
||||||
|
.xarxaprod-filtered-funds .os_fund_field .filter {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -42,7 +42,7 @@ if( ! function_exists( 'xarxaprod_ajuts_filters_form') ) {
|
||||||
if( $fields ) {
|
if( $fields ) {
|
||||||
|
|
||||||
// check for values from meta fields db in url
|
// check for values from meta fields db in url
|
||||||
foreach( $GLOBALS['my_query_filters_ajut'] as $key => $fieldname ) {
|
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ) {
|
||||||
|
|
||||||
// check for values in url and get value if available
|
// check for values in url and get value if available
|
||||||
if( isset($_GET[ $fieldname ]) ) {
|
if( isset($_GET[ $fieldname ]) ) {
|
||||||
|
|
|
@ -14,21 +14,21 @@
|
||||||
|
|
||||||
// define the filter fields
|
// define the filter fields
|
||||||
// array of filters (field key => field name)
|
// array of filters (field key => field name)
|
||||||
$GLOBALS['my_query_filters_ajut'] = array(
|
$GLOBALS['my_query_filters'] = array(
|
||||||
'fundtarget' => 'xxp_fund_target',
|
'fundtarget' => 'os_fund_target',
|
||||||
'fundsource' => 'xxp_fund_source',
|
'fundsource' => 'os_fund_source',
|
||||||
'fundfield' => 'xxp_fund_field'
|
'fundfield' => 'os_fund_field'
|
||||||
);
|
);
|
||||||
$GLOBALS['my_query_filters_ajut_dates'] = array(
|
$GLOBALS['my_query_filters_dates'] = array(
|
||||||
'fundapplybegin' => 'xxp_fund_apply_begin',
|
'fundapplybegin' => 'os_fund_apply_begin',
|
||||||
'fundapplyend' => 'xxp_fund_apply_end'
|
'fundapplyend' => 'os_fund_apply_end'
|
||||||
//'fundcall' => 'xxp_fund_call',
|
//'fundcall' => 'os_fund_call',
|
||||||
);
|
);
|
||||||
|
|
||||||
// action
|
// action
|
||||||
add_action('pre_get_posts', 'my_pre_get_posts_ajuts',10,1);
|
add_action('pre_get_posts', 'my_pre_get_posts',10,1);
|
||||||
if ( ! function_exists('my_pre_get_posts_ajuts') ){
|
|
||||||
function my_pre_get_posts_ajuts( $query ) {
|
function my_pre_get_posts( $query ) {
|
||||||
|
|
||||||
// bail early if is in admin
|
// bail early if is in admin
|
||||||
if( is_admin() ) { return; }
|
if( is_admin() ) { return; }
|
||||||
|
@ -40,7 +40,7 @@ if ( ! function_exists('my_pre_get_posts_ajuts') ){
|
||||||
|
|
||||||
|
|
||||||
// loop over filters
|
// loop over filters
|
||||||
foreach( $GLOBALS['my_query_filters_ajut'] as $key => $fieldname)
|
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname)
|
||||||
{
|
{
|
||||||
// continue if not found in url
|
// continue if not found in url
|
||||||
if( empty($_GET[ $fieldname ]) ) { continue; }
|
if( empty($_GET[ $fieldname ]) ) { continue; }
|
||||||
|
@ -51,12 +51,12 @@ if ( ! function_exists('my_pre_get_posts_ajuts') ){
|
||||||
$meta_query[] = array('relation' => 'OR');
|
$meta_query[] = array('relation' => 'OR');
|
||||||
|
|
||||||
// get the values for this filter
|
// get the values for this filter
|
||||||
// eg: http://domain.tdl/ajut/?xxp_fund_target=autonoma,entitat-publica
|
// eg: http://domain.tdl/ajut/?os_fund_target=autonoma,entitat-publica
|
||||||
$filtervalues= explode(',', $_GET[ $fieldname ]);
|
$filtervalues= explode(',', $_GET[ $fieldname ]);
|
||||||
|
|
||||||
// loop retreived values from checkboxes and filter them with REGEXP
|
// loop retreived values from checkboxes and filter them with REGEXP
|
||||||
// http://domain.tdl/ajut/?xxp_fund_target=autonoma&xxp_fund_field=circi
|
// http://domain.tdl/ajut/?os_fund_target=autonoma&os_fund_field=circi
|
||||||
// http://domain.tdl/ajut/?xxp_fund_target=autonoma,entitat-publica&xxp_fund_field=dansa
|
// http://domain.tdl/ajut/?os_fund_target=autonoma,entitat-publica&os_fund_field=dansa
|
||||||
foreach( $filtervalues as $filteredvalue )
|
foreach( $filtervalues as $filteredvalue )
|
||||||
{
|
{
|
||||||
// they are array based fields
|
// they are array based fields
|
||||||
|
@ -78,5 +78,4 @@ if ( ! function_exists('my_pre_get_posts_ajuts') ){
|
||||||
|
|
||||||
//always return
|
//always return
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,180 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Function to display the front end checkboxes for the associat filter
|
|
||||||
*
|
|
||||||
* references:
|
|
||||||
* basic start
|
|
||||||
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
|
||||||
*
|
|
||||||
* wordpress full form example
|
|
||||||
* https://wordpress.stackexchange.com/questions/383599/form-checkbox-value-going-to-dynamic-url
|
|
||||||
*
|
|
||||||
* checkbox adaptation query
|
|
||||||
* https://wordpress.stackexchange.com/a/102915
|
|
||||||
*
|
|
||||||
* form GET and POST
|
|
||||||
* https://www.formget.com/php-checkbox/
|
|
||||||
*
|
|
||||||
* @package Xarxaprod_wp_plugin
|
|
||||||
*/
|
|
||||||
?>
|
|
||||||
<?php
|
|
||||||
if( ! function_exists( 'xarxaprod_associats_filters_form') ) {
|
|
||||||
function xarxaprod_associats_filters_form() {
|
|
||||||
?>
|
|
||||||
<div id="archive-filters" class="xarxaprod-filters">
|
|
||||||
<?php
|
|
||||||
// output all possible values of a checkbox
|
|
||||||
$groupkey = "group_65d86bf0666a2"; // write here the key for the group of fields from acf
|
|
||||||
if( $groupkey ) {
|
|
||||||
?>
|
|
||||||
<?php // start the form ?>
|
|
||||||
<form id="form-associats" name="search-associats">
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$groupkey_fields = acf_get_fields($groupkey);
|
|
||||||
foreach( $groupkey_fields as $field_key ) {
|
|
||||||
|
|
||||||
if( $field_key['type'] == 'checkbox' ){
|
|
||||||
|
|
||||||
// https://wordpress.stackexchange.com/a/102915
|
|
||||||
$fields = get_field_object($field_key['key']);
|
|
||||||
if( $fields ) {
|
|
||||||
|
|
||||||
// check for values from meta fields db in url
|
|
||||||
foreach( $GLOBALS['my_query_filters_associat'] as $key => $fieldname ) {
|
|
||||||
|
|
||||||
// check for values in url and get value if available
|
|
||||||
if( isset($_GET[ $fieldname ]) ) {
|
|
||||||
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
|
||||||
} else {
|
|
||||||
$filteredvalues['value'] = [];
|
|
||||||
};
|
|
||||||
//end check for values in url
|
|
||||||
|
|
||||||
// construct the checkboxes
|
|
||||||
if( $fieldname == $fields['name']) {
|
|
||||||
?>
|
|
||||||
|
|
||||||
<section id="call-filter call-filter-<?php echo $fields['name']; ?>" class="<?php echo $fields['name']; ?>">
|
|
||||||
<h5 class="xarxaprod-titol-opcions"><?php echo $fields['label'];?></h5>
|
|
||||||
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
|
||||||
|
|
||||||
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
|
||||||
<input class="xarxaprod-filter" type="checkbox" name="<?php echo $fields['name'];?>" <?php if( in_array( $choicevalue, $filteredvalues['value']) ) { echo 'checked'; } ?> value="<?php echo $choicevalue; ?>" />
|
|
||||||
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php };//end foreach fields['choices'] ?>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<?php }; //end if fieldname == fields['name'] ?>
|
|
||||||
<?php // end of construct checkboxes ?>
|
|
||||||
|
|
||||||
<?php }; // end check for values from meta fields db in url ?>
|
|
||||||
|
|
||||||
<?php }; //end if field_key['key'] ?>
|
|
||||||
|
|
||||||
<?php }; //end if type checkbox ?>
|
|
||||||
|
|
||||||
<?php }; //end foreach groupkey field ?>
|
|
||||||
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
|
||||||
<p><a id="submitfilteredlink" name="submit-associat" class="button button-more" href="">enviar</a> </p>
|
|
||||||
</form>
|
|
||||||
<?php //close the form and subit ?>
|
|
||||||
|
|
||||||
<?php }; //end if groupkey ?>
|
|
||||||
<aside id="search-form-associats" class="xarxaprod-search-associats">
|
|
||||||
<?php
|
|
||||||
// search form for custom post type 'xarxaprod-associat'
|
|
||||||
// <input type="hidden" value="xarxaprod-associat" name="post_type" id="post_type" />
|
|
||||||
// https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
|
|
||||||
// https://wordpress.stackexchange.com/questions/313037/restrict-a-sear ch-to-a-custom-post-type
|
|
||||||
?>
|
|
||||||
<form class="xarxaprod-search-form" role="search" method="get" action="/">
|
|
||||||
<label class="screen-reader-text" for="search">Search in associats</label>
|
|
||||||
<input type="search" id="search" class="search-field" placeholder="cerca amb paraula clau..." value="<?php the_search_query(); ?>" name="s" />
|
|
||||||
<input type="submit" id="searchsubmit" class="search-submit" value="cerca">
|
|
||||||
<span class="xarxaprod-search-submit xarxaprod-icon-search"></span>
|
|
||||||
<input type="hidden" value="xarxaprod-associat" name="post_type" id="post_type" />
|
|
||||||
</form>
|
|
||||||
</aside>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
(function($) {
|
|
||||||
// https://stackoverflow.com/a/12025482
|
|
||||||
// change
|
|
||||||
$('#archive-filters').on('click', 'input', function(){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var url = '<?php echo home_url('associats/'); ?>';
|
|
||||||
args = {};
|
|
||||||
var appendtoURL = '';
|
|
||||||
var eachfiltered = '';
|
|
||||||
var valueschecked = '';
|
|
||||||
|
|
||||||
// loop over filters
|
|
||||||
$('#archive-filters .filter').each(function(){
|
|
||||||
// check if is first appearance of each
|
|
||||||
if( eachfiltered != $(this).data('filter') ){
|
|
||||||
// save already calculated field=val01,val02,val03
|
|
||||||
if( eachfiltered != '' && valueschecked != '' ){
|
|
||||||
// remove last ','
|
|
||||||
valueschecked = valueschecked.slice(0, -1);
|
|
||||||
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
|
||||||
};
|
|
||||||
// start new fieldname filtered
|
|
||||||
eachfiltered = $(this).data('filter');
|
|
||||||
// reset values
|
|
||||||
valueschecked = '';
|
|
||||||
// find checked inputs
|
|
||||||
$(this).find('input:checked').each(function(){
|
|
||||||
// if not empty save value and ,
|
|
||||||
if( $(this).val() != '' ){
|
|
||||||
valueschecked += $(this).val() + ',';
|
|
||||||
};
|
|
||||||
});
|
|
||||||
//alert( appendtoURL +":" +eachfiltered +"=" +valuescheked);
|
|
||||||
} else {
|
|
||||||
// we have previous values checked
|
|
||||||
// find checked inputs
|
|
||||||
//if( $(this).val() != '' ){
|
|
||||||
// if not empty append value and ,
|
|
||||||
$(this).find('input:checked').each(function(){
|
|
||||||
valueschecked += $(this).val() + ',';
|
|
||||||
});
|
|
||||||
//alert( appendtoURL +":not:" +eachfiltered +"=" +valuescheked);
|
|
||||||
//};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove last ','
|
|
||||||
valueschecked = valueschecked.slice(0, -1);
|
|
||||||
// save last cycled filtered value already calculated field=val01,val02,val03
|
|
||||||
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
|
||||||
|
|
||||||
// remove last &
|
|
||||||
appendtoURL = appendtoURL.slice(0, -1);
|
|
||||||
|
|
||||||
// update url
|
|
||||||
url += '?' +appendtoURL;
|
|
||||||
|
|
||||||
// show or modify the url
|
|
||||||
//alert( url );
|
|
||||||
//$('#filterlink').text(url);
|
|
||||||
|
|
||||||
// convert a href url to new value
|
|
||||||
$('#submitfilteredlink').attr('href',url);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
})(jQuery);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
|
||||||
}; //end xarxaprod_associats_filters_form
|
|
||||||
}; // end if ! functions_exists
|
|
||||||
?>
|
|
|
@ -1,84 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Makes a filter for the custom post type associats and its custom fields
|
|
||||||
*
|
|
||||||
* references:
|
|
||||||
* basic start
|
|
||||||
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
|
||||||
*
|
|
||||||
* checkbox adaptation query filter
|
|
||||||
* https://barn2.com/blog/querying-posts-by-custom-field-acf/#array-based-fields
|
|
||||||
*
|
|
||||||
* @package Xarxaprod_wp_plugin
|
|
||||||
*/
|
|
||||||
|
|
||||||
// define the filter fields
|
|
||||||
// array of filters (field key => field name)
|
|
||||||
$GLOBALS['my_query_filters_associat'] = array(
|
|
||||||
'associatfield' => 'xxp_associat_field', //disciplines
|
|
||||||
'associatterritory' => 'xxp_associat_territory', //territori
|
|
||||||
'associatservice' => 'xxp_associat_service', //serveis
|
|
||||||
'associatcenter' => 'xxp_associat_center' //centre
|
|
||||||
|
|
||||||
);
|
|
||||||
$GLOBALS['my_query_filters_associat_dates'] = array(
|
|
||||||
'associatapplybegin' => 'xxp_associat_apply_begin',
|
|
||||||
'associatapplyend' => 'xxp_associat_apply_end'
|
|
||||||
//'associatcall' => 'xxp_associat_call',
|
|
||||||
);
|
|
||||||
|
|
||||||
// action
|
|
||||||
add_action('pre_get_posts', 'my_pre_get_posts_associats',10,1);
|
|
||||||
if ( ! function_exists( 'my_pre_get_posts_associats' ) ){
|
|
||||||
function my_pre_get_posts_associats( $query ) {
|
|
||||||
|
|
||||||
// bail early if is in admin
|
|
||||||
if( is_admin() ) { return; }
|
|
||||||
|
|
||||||
// bail early if not main query or plugin $the_query_associat
|
|
||||||
// - allows custom code / plugins to continue working
|
|
||||||
if( !$query->is_main_query() ) return;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// loop over filters
|
|
||||||
foreach( $GLOBALS['my_query_filters_associat'] as $key => $fieldname)
|
|
||||||
{
|
|
||||||
// continue if not found in url
|
|
||||||
if( empty($_GET[ $fieldname ]) ) { continue; }
|
|
||||||
|
|
||||||
// get original meta query
|
|
||||||
$meta_query = [];
|
|
||||||
$meta_query[] = $query->get('meta_query');
|
|
||||||
$meta_query[] = array('relation' => 'OR');
|
|
||||||
|
|
||||||
// get the values for this filter
|
|
||||||
// eg: http://domain.tdl/associat/?xxp_associat_target=autonoma,entitat-publica
|
|
||||||
$filtervalues= explode(',', $_GET[ $fieldname ]);
|
|
||||||
|
|
||||||
// loop retreived values from checkboxes and filter them with REGEXP
|
|
||||||
// http://domain.tdl/associat/?xxp_associat_target=autonoma&xxp_associat_field=circi
|
|
||||||
// http://domain.tdl/associat/?xxp_associat_target=autonoma,entitat-publica&xxp_associat_field=dansa
|
|
||||||
foreach( $filtervalues as $filteredvalue )
|
|
||||||
{
|
|
||||||
// they are array based fields
|
|
||||||
// https://barn2.com/blog/querying-posts-by-custom-field-acf/#array-based-fields
|
|
||||||
$strippedvalue = sprintf( '^%1$s$|s:%2$u:"%1$s";', $filteredvalue, strlen( $filteredvalue ) );
|
|
||||||
|
|
||||||
// add our meta query to the original meta queries
|
|
||||||
$meta_query[] = array(
|
|
||||||
array(
|
|
||||||
'key' => $fieldname,
|
|
||||||
'value' => $strippedvalue,
|
|
||||||
'compare' => 'REGEXP',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// update the meta query arguments
|
|
||||||
$query->set('meta_query', $meta_query);
|
|
||||||
}
|
|
||||||
|
|
||||||
//always return
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,180 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Function to display the front end checkboxes for the convo filter
|
|
||||||
*
|
|
||||||
* references:
|
|
||||||
* basic start
|
|
||||||
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
|
||||||
*
|
|
||||||
* wordpress full form example
|
|
||||||
* https://wordpress.stackexchange.com/questions/383599/form-checkbox-value-going-to-dynamic-url
|
|
||||||
*
|
|
||||||
* checkbox adaptation query
|
|
||||||
* https://wordpress.stackexchange.com/a/102915
|
|
||||||
*
|
|
||||||
* form GET and POST
|
|
||||||
* https://www.formget.com/php-checkbox/
|
|
||||||
*
|
|
||||||
* @package Xarxaprod_wp_plugin
|
|
||||||
*/
|
|
||||||
?>
|
|
||||||
<?php
|
|
||||||
if( ! function_exists( 'xarxaprod_convos_filters_form') ) {
|
|
||||||
function xarxaprod_convos_filters_form() {
|
|
||||||
?>
|
|
||||||
<div id="archive-filters" class="xarxaprod-filters">
|
|
||||||
<?php
|
|
||||||
// output all possible values of a checkbox
|
|
||||||
$groupkey = "group_65abb25b84079"; // write here the key for the group of fields from acf
|
|
||||||
if( $groupkey ) {
|
|
||||||
?>
|
|
||||||
<?php // start the form ?>
|
|
||||||
<form id="form-convos" name="search-convos">
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$groupkey_fields = acf_get_fields($groupkey);
|
|
||||||
foreach( $groupkey_fields as $field_key ) {
|
|
||||||
|
|
||||||
if( $field_key['type'] == 'checkbox' ){
|
|
||||||
|
|
||||||
// https://wordpress.stackexchange.com/a/102915
|
|
||||||
$fields = get_field_object($field_key['key']);
|
|
||||||
if( $fields ) {
|
|
||||||
|
|
||||||
// check for values from meta fields db in url
|
|
||||||
foreach( $GLOBALS['my_query_filters_convo'] as $key => $fieldname ) {
|
|
||||||
|
|
||||||
// check for values in url and get value if available
|
|
||||||
if( isset($_GET[ $fieldname ]) ) {
|
|
||||||
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
|
||||||
} else {
|
|
||||||
$filteredvalues['value'] = [];
|
|
||||||
};
|
|
||||||
//end check for values in url
|
|
||||||
|
|
||||||
// construct the checkboxes
|
|
||||||
if( $fieldname == $fields['name']) {
|
|
||||||
?>
|
|
||||||
|
|
||||||
<section id="call-filter call-filter-<?php echo $fields['name']; ?>" class="<?php echo $fields['name']; ?>">
|
|
||||||
<h5 class="xarxaprod-titol-opcions"><?php echo $fields['label'];?></h5>
|
|
||||||
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
|
||||||
|
|
||||||
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
|
||||||
<input class="xarxaprod-filter" type="checkbox" name="<?php echo $fields['name'];?>" <?php if( in_array( $choicevalue, $filteredvalues['value']) ) { echo 'checked'; } ?> value="<?php echo $choicevalue; ?>" />
|
|
||||||
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php };//end foreach fields['choices'] ?>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<?php }; //end if fieldname == fields['name'] ?>
|
|
||||||
<?php // end of construct checkboxes ?>
|
|
||||||
|
|
||||||
<?php }; // end check for values from meta fields db in url ?>
|
|
||||||
|
|
||||||
<?php }; //end if field_key['key'] ?>
|
|
||||||
|
|
||||||
<?php }; //end if type checkbox ?>
|
|
||||||
|
|
||||||
<?php }; //end foreach groupkey field ?>
|
|
||||||
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
|
||||||
<p><a id="submitfilteredlink" name="submit-convo" class="button button-more" href="">enviar</a> </p>
|
|
||||||
</form>
|
|
||||||
<?php //close the form and subit ?>
|
|
||||||
|
|
||||||
<?php }; //end if groupkey ?>
|
|
||||||
<aside id="search-form-convos" class="xarxaprod-search-convos">
|
|
||||||
<?php
|
|
||||||
// search form for custom post type 'xarxaprod-convo'
|
|
||||||
// <input type="hidden" value="xarxaprod-convo" name="post_type" id="post_type" />
|
|
||||||
// https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
|
|
||||||
// https://wordpress.stackexchange.com/questions/313037/restrict-a-sear ch-to-a-custom-post-type
|
|
||||||
?>
|
|
||||||
<form class="xarxaprod-search-form" role="search" method="get" action="/">
|
|
||||||
<label class="screen-reader-text" for="search">Search in convos</label>
|
|
||||||
<input type="search" id="search" class="search-field" placeholder="cerca amb paraula clau..." value="<?php the_search_query(); ?>" name="s" />
|
|
||||||
<input type="submit" id="searchsubmit" class="search-submit" value="cerca">
|
|
||||||
<span class="xarxaprod-search-submit xarxaprod-icon-search"></span>
|
|
||||||
<input type="hidden" value="xarxaprod-convo" name="post_type" id="post_type" />
|
|
||||||
</form>
|
|
||||||
</aside>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
(function($) {
|
|
||||||
// https://stackoverflow.com/a/12025482
|
|
||||||
// change
|
|
||||||
$('#archive-filters').on('click', 'input', function(){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var url = '<?php echo home_url('convos/'); ?>';
|
|
||||||
args = {};
|
|
||||||
var appendtoURL = '';
|
|
||||||
var eachfiltered = '';
|
|
||||||
var valueschecked = '';
|
|
||||||
|
|
||||||
// loop over filters
|
|
||||||
$('#archive-filters .filter').each(function(){
|
|
||||||
// check if is first appearance of each
|
|
||||||
if( eachfiltered != $(this).data('filter') ){
|
|
||||||
// save already calculated field=val01,val02,val03
|
|
||||||
if( eachfiltered != '' && valueschecked != '' ){
|
|
||||||
// remove last ','
|
|
||||||
valueschecked = valueschecked.slice(0, -1);
|
|
||||||
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
|
||||||
};
|
|
||||||
// start new fieldname filtered
|
|
||||||
eachfiltered = $(this).data('filter');
|
|
||||||
// reset values
|
|
||||||
valueschecked = '';
|
|
||||||
// find checked inputs
|
|
||||||
$(this).find('input:checked').each(function(){
|
|
||||||
// if not empty save value and ,
|
|
||||||
if( $(this).val() != '' ){
|
|
||||||
valueschecked += $(this).val() + ',';
|
|
||||||
};
|
|
||||||
});
|
|
||||||
//alert( appendtoURL +":" +eachfiltered +"=" +valuescheked);
|
|
||||||
} else {
|
|
||||||
// we have previous values checked
|
|
||||||
// find checked inputs
|
|
||||||
//if( $(this).val() != '' ){
|
|
||||||
// if not empty append value and ,
|
|
||||||
$(this).find('input:checked').each(function(){
|
|
||||||
valueschecked += $(this).val() + ',';
|
|
||||||
});
|
|
||||||
//alert( appendtoURL +":not:" +eachfiltered +"=" +valuescheked);
|
|
||||||
//};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove last ','
|
|
||||||
valueschecked = valueschecked.slice(0, -1);
|
|
||||||
// save last cycled filtered value already calculated field=val01,val02,val03
|
|
||||||
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
|
||||||
|
|
||||||
// remove last &
|
|
||||||
appendtoURL = appendtoURL.slice(0, -1);
|
|
||||||
|
|
||||||
// update url
|
|
||||||
url += '?' +appendtoURL;
|
|
||||||
|
|
||||||
// show or modify the url
|
|
||||||
//alert( url );
|
|
||||||
//$('#filterlink').text(url);
|
|
||||||
|
|
||||||
// convert a href url to new value
|
|
||||||
$('#submitfilteredlink').attr('href',url);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
})(jQuery);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
|
||||||
}; //end xarxaprod_convos_filters_form
|
|
||||||
}; // end if ! functions_exists
|
|
||||||
?>
|
|
|
@ -1,84 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Makes a filter for the custom post type convo and its custom fields
|
|
||||||
*
|
|
||||||
* references:
|
|
||||||
* basic start
|
|
||||||
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
|
||||||
*
|
|
||||||
* checkbox adaptation query filter
|
|
||||||
* https://barn2.com/blog/querying-posts-by-custom-field-acf/#array-based-fields
|
|
||||||
*
|
|
||||||
* @package Xarxaprod_wp_plugin
|
|
||||||
*/
|
|
||||||
|
|
||||||
// define the filter fields
|
|
||||||
// array of filters (field key => field name)
|
|
||||||
$GLOBALS['my_query_filters_convo'] = array(
|
|
||||||
'convofield' => 'xxp_convo_field', //disciplines
|
|
||||||
'convoterritory' => 'xxp_convo_territory', //territori
|
|
||||||
'convoservice' => 'xxp_convo_service', //serveis
|
|
||||||
'convocenter' => 'xxp_convo_center' //centre
|
|
||||||
|
|
||||||
);
|
|
||||||
$GLOBALS['my_query_filters_convo_dates'] = array(
|
|
||||||
'convoapplybegin' => 'xxp_convo_apply_begin',
|
|
||||||
'convoapplyend' => 'xxp_convo_apply_end'
|
|
||||||
//'convocall' => 'xxp_convo_call',
|
|
||||||
);
|
|
||||||
|
|
||||||
// action
|
|
||||||
add_action('pre_get_posts', 'my_pre_get_posts_convos',10,1);
|
|
||||||
if ( ! function_exists( 'my_pre_get_posts_convos' ) ){
|
|
||||||
function my_pre_get_posts_convos( $query ) {
|
|
||||||
|
|
||||||
// bail early if is in admin
|
|
||||||
if( is_admin() ) { return; }
|
|
||||||
|
|
||||||
// bail early if not main query or plugin $the_query_convo
|
|
||||||
// - allows custom code / plugins to continue working
|
|
||||||
if( !$query->is_main_query() ) return;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// loop over filters
|
|
||||||
foreach( $GLOBALS['my_query_filters_convo'] as $key => $fieldname)
|
|
||||||
{
|
|
||||||
// continue if not found in url
|
|
||||||
if( empty($_GET[ $fieldname ]) ) { continue; }
|
|
||||||
|
|
||||||
// get original meta query
|
|
||||||
$meta_query = [];
|
|
||||||
$meta_query[] = $query->get('meta_query');
|
|
||||||
$meta_query[] = array('relation' => 'OR');
|
|
||||||
|
|
||||||
// get the values for this filter
|
|
||||||
// eg: http://domain.tdl/convo/?xxp_convo_target=autonoma,entitat-publica
|
|
||||||
$filtervalues= explode(',', $_GET[ $fieldname ]);
|
|
||||||
|
|
||||||
// loop retreived values from checkboxes and filter them with REGEXP
|
|
||||||
// http://domain.tdl/convo/?xxp_convo_target=autonoma&xxp_convo_field=circi
|
|
||||||
// http://domain.tdl/convo/?xxp_convo_target=autonoma,entitat-publica&xxp_convo_field=dansa
|
|
||||||
foreach( $filtervalues as $filteredvalue )
|
|
||||||
{
|
|
||||||
// they are array based fields
|
|
||||||
// https://barn2.com/blog/querying-posts-by-custom-field-acf/#array-based-fields
|
|
||||||
$strippedvalue = sprintf( '^%1$s$|s:%2$u:"%1$s";', $filteredvalue, strlen( $filteredvalue ) );
|
|
||||||
|
|
||||||
// add our meta query to the original meta queries
|
|
||||||
$meta_query[] = array(
|
|
||||||
array(
|
|
||||||
'key' => $fieldname,
|
|
||||||
'value' => $strippedvalue,
|
|
||||||
'compare' => 'REGEXP',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// update the meta query arguments
|
|
||||||
$query->set('meta_query', $meta_query);
|
|
||||||
}
|
|
||||||
|
|
||||||
//always return
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
|
|
||||||
// Register Custom Post Type
|
// Register Custom Post Type
|
||||||
if ( ! function_exists('xarxaprod_wpplugin_custom_post_ajut_init') ){
|
|
||||||
function xarxaprod_wpplugin_custom_post_ajut_init() {
|
function xarxaprod_wpplugin_custom_post_ajut_init() {
|
||||||
|
|
||||||
$labels = array(
|
$labels = array(
|
||||||
|
@ -86,19 +85,16 @@ if ( ! function_exists('xarxaprod_wpplugin_custom_post_ajut_init') ){
|
||||||
);
|
);
|
||||||
register_post_type( 'xarxaprod-ajut', $args );
|
register_post_type( 'xarxaprod-ajut', $args );
|
||||||
}
|
}
|
||||||
}// end function_exists xarxaprod_wpplugin_custom_post_ajut_init
|
|
||||||
// Hook into the 'init' action
|
// Hook into the 'init' action
|
||||||
add_action( 'init', 'xarxaprod_wpplugin_custom_post_ajut_init', 0 );
|
add_action( 'init', 'xarxaprod_wpplugin_custom_post_ajut_init', 0 );
|
||||||
|
|
||||||
|
|
||||||
// flush rewrite and when changing theme or plugin
|
// flush rewrite and when changing theme or plugin
|
||||||
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
|
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
|
||||||
if ( ! function_exists( 'xarxaprod_ajut_rewrite_flush') ){
|
|
||||||
function xarxaprod_ajut_rewrite_flush() {
|
function xarxaprod_ajut_rewrite_flush() {
|
||||||
xarxaprod_wpplugin_custom_post_ajut_init();
|
xarxaprod_wpplugin_custom_post_ajut_init();
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
}
|
}
|
||||||
}// end function_exists xarxaprod_ajut_rewrite_flush
|
|
||||||
add_action( 'after_switch_theme', 'xarxaprod_ajut_rewrite_flush' );
|
add_action( 'after_switch_theme', 'xarxaprod_ajut_rewrite_flush' );
|
||||||
|
|
||||||
// give capabilities once the custom post id activated
|
// give capabilities once the custom post id activated
|
||||||
|
|
|
@ -1,241 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Custom post type Espais Associats.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @link https://xarxaprod.cat
|
|
||||||
* @since 1.0.0
|
|
||||||
* @package xarxaprod-wp-plugin
|
|
||||||
* @subpackage xarxaprod-wp-plugin/includes
|
|
||||||
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
|
||||||
*
|
|
||||||
* @internal never define functions inside callbacks.
|
|
||||||
* these functions could be run multiple times; this would result in a fatal error.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start custom post types
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/
|
|
||||||
* https://developer.wordpress.org/reference/functions/register_post_type/
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Register Custom Post Type
|
|
||||||
if ( ! function_exists('xarxaprod_wpplugin_custom_post_associat_init') ){
|
|
||||||
function xarxaprod_wpplugin_custom_post_associat_init() {
|
|
||||||
|
|
||||||
$labels = array(
|
|
||||||
'name' => _x( 'Associats', 'Post Tipu General Name', 'text_domain' ),
|
|
||||||
'singular_name' => _x( 'Associat', 'Post Tipu Singular Name', 'text_domain' ),
|
|
||||||
'menu_name' => __( 'Associats', 'text_domain' ),
|
|
||||||
'parent_item_colon' => __( 'Associats mare/pare:', 'text_domain' ),
|
|
||||||
'all_items' => __( 'Tots els associats', 'text_domain' ),
|
|
||||||
'view_item' => __( 'Mostra els associats', 'text_domain' ),
|
|
||||||
'add_new_item' => __( 'Affegeix un associat', 'text_domain' ),
|
|
||||||
'add_new' => __( 'Affegeix associat', 'text_domain' ),
|
|
||||||
'edit_item' => __( 'Edita associat', 'text_domain' ),
|
|
||||||
'update_item' => __( 'Desa associat', 'text_domain' ),
|
|
||||||
'search_items' => __( 'Cerca associat', 'text_domain' ),
|
|
||||||
'not_associat' => __( 'No hem pogut trovar ningúna associat', 'text_domain' ),
|
|
||||||
'not_associat_in_trash' => __( 'No hem trovat cap associat a la brosa', 'text_domain' )
|
|
||||||
);
|
|
||||||
$rewrite = array(
|
|
||||||
'slug' => 'associat'
|
|
||||||
);
|
|
||||||
// https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375
|
|
||||||
// https://developer.wordpress.org/reference/functions/register_post_type/#capability_type
|
|
||||||
//$capabilities = array(
|
|
||||||
// 'read' => 'read_associat',
|
|
||||||
// 'publish_posts' => 'publish_associat',
|
|
||||||
// 'edit_posts' => 'edit_associat',
|
|
||||||
// 'edit_published_posts' => 'edit_published_associat',
|
|
||||||
// 'edit_others_posts' => 'edit_others_associat',
|
|
||||||
// 'delete_posts' => 'delete_associat',
|
|
||||||
// 'delete_published_posts' => 'delete_published_associat',
|
|
||||||
// 'delete_others_posts' => 'delete_others_associat',
|
|
||||||
// 'delete_private_posts' => 'delete_private_associat'
|
|
||||||
// );
|
|
||||||
$args = array(
|
|
||||||
'label' => __( 'xarxaprod-associat', 'text_domain' ),
|
|
||||||
'description' => __( 'Associats', 'text_domain' ),
|
|
||||||
'labels' => $labels,
|
|
||||||
//'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
|
||||||
'supports' => array( 'title', 'editor', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
|
||||||
// 'taxonomies' => array(
|
|
||||||
// 'xarxaprod-associat-category',
|
|
||||||
// 'xarxaprod-associat-tag'
|
|
||||||
// ),
|
|
||||||
'hierarchical' => true,
|
|
||||||
'public' => true,
|
|
||||||
'show_ui' => true,
|
|
||||||
'show_in_menu' => true,
|
|
||||||
'show_in_nav_menus' => true,
|
|
||||||
'show_in_admin_bar' => true,
|
|
||||||
'show_in_rest' => true,
|
|
||||||
'menu_position' => 5,
|
|
||||||
'menu_icon' => 'dashicons-groups',
|
|
||||||
'can_export' => true,
|
|
||||||
'has_archive' => true,
|
|
||||||
'exclude_from_search' => false,
|
|
||||||
'publicly_queryable' => true,
|
|
||||||
'capability_type' => 'post',
|
|
||||||
'rewrite' => $rewrite,
|
|
||||||
//'capabilities' => $capabilities,
|
|
||||||
//'map_meta_cap' => true //neded to apply the new capabilities.
|
|
||||||
);
|
|
||||||
register_post_type( 'xarxaprod-associat', $args );
|
|
||||||
}
|
|
||||||
}// end function_exists xarxaprod_wpplugin_custom_post_associat_init
|
|
||||||
// Hook into the 'init' action
|
|
||||||
add_action( 'init', 'xarxaprod_wpplugin_custom_post_associat_init', 0 );
|
|
||||||
|
|
||||||
|
|
||||||
// flush rewrite and when changing theme or plugin
|
|
||||||
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
|
|
||||||
if ( ! function_exists( 'xarxaprod_associat_rewrite_flush') ){
|
|
||||||
function xarxaprod_associat_rewrite_flush() {
|
|
||||||
xarxaprod_wpplugin_custom_post_associat_init();
|
|
||||||
flush_rewrite_rules();
|
|
||||||
}
|
|
||||||
}// end function_exists xarxaprod_associat_rewrite_flush
|
|
||||||
add_action( 'after_switch_theme', 'xarxaprod_associat_rewrite_flush' );
|
|
||||||
|
|
||||||
// give capabilities once the custom post id activated
|
|
||||||
// function xarxaprod_wpplugin_add_caps() {
|
|
||||||
// gets the XX role
|
|
||||||
// $admins = get_role( '' );
|
|
||||||
// $admins->add_cap( );
|
|
||||||
// gets the administrator role
|
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
//add_action( 'admin_init', 'xarxaprod_wpplugin_add_caps');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start custom taxonomies
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/
|
|
||||||
* https://developer.wordpress.org/reference/functions/register_taxonomy/
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Register Custom Taxonomy Category for Associats
|
|
||||||
//function xarxaprod_wpplugin_associat_category_register() {
|
|
||||||
|
|
||||||
// $labels = array(
|
|
||||||
// 'name' => _x( 'Associats Tipus', 'Taxonomy General Name', 'text_domain' ),
|
|
||||||
// 'singular_name' => _x( 'Tipus d`associat', 'Taxonomy Singular Name', 'text_domain' ),
|
|
||||||
// 'menu_name' => __( 'Associats Tipus', 'text_domain' ),
|
|
||||||
// 'all_items' => __( 'All type associat', 'text_domain' ),
|
|
||||||
// 'parent_item' => __( 'Parent type associat', 'text_domain' ),
|
|
||||||
// 'parent_item_colon' => __( 'Parent type associat:', 'text_domain' ),
|
|
||||||
// 'new_item_name' => __( 'New type associat', 'text_domain' ),
|
|
||||||
// 'add_new_item' => __( 'Add New type associat', 'text_domain' ),
|
|
||||||
// 'edit_item' => __( 'Edit type associat', 'text_domain' ),
|
|
||||||
// 'update_item' => __( 'Update type of associat', 'text_domain' ),
|
|
||||||
// 'separate_items_with_commas' => __( 'Separate type associat with commas', 'text_domain' ),
|
|
||||||
// 'search_items' => __( 'Search type of associat', 'text_domain' ),
|
|
||||||
// 'add_or_remove_items' => __( 'Add or remove type of associat', 'text_domain' ),
|
|
||||||
// 'choose_from_most_used' => __( 'Choose from the most used type of associat', 'text_domain' ),
|
|
||||||
// 'not_associat' => __( 'Tipus d`associat Not Associat', 'text_domain' )
|
|
||||||
// );
|
|
||||||
// $rewrite = array(
|
|
||||||
// 'slug' => 'associat-tipus'
|
|
||||||
// );
|
|
||||||
// //$capabilities = array(
|
|
||||||
// // 'manage_terms' => 'Xarxaprod Manage associat Tipus',
|
|
||||||
// // 'edit_terms' => 'Xarxaprod Edit associat Tipus',
|
|
||||||
// // 'delete_terms' => 'Xarxaprod Delete associat Tipus',
|
|
||||||
// // 'assign_terms' => 'Xarxaprod Assign associat Tipus',
|
|
||||||
// // );
|
|
||||||
// $args = array(
|
|
||||||
// 'labels' => $labels,
|
|
||||||
// 'hierarchical' => true,
|
|
||||||
// 'public' => true,
|
|
||||||
// 'show_ui' => true,
|
|
||||||
// 'show_admin_column' => true,
|
|
||||||
// 'show_in_nav_menus' => true,
|
|
||||||
// 'show_tagcloud' => false,
|
|
||||||
// 'rewrite' => $rewrite,
|
|
||||||
// //'capabilities' => $capabilities,
|
|
||||||
// 'map_meta_cap' => true //neded to apply the new capabilities.
|
|
||||||
|
|
||||||
// );
|
|
||||||
// register_taxonomy( 'xarxaprod-associat-category', array( 'xarxaprod-associat' ) , $args );
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Hook into the 'init' action
|
|
||||||
//add_action( 'init', 'xarxaprod_wpplugin_associat_category_register', 0 );
|
|
||||||
|
|
||||||
// Register Custom Taxonomy Tag for Associats
|
|
||||||
// function xarxaprod_wpplugin_associat_tag_register() {
|
|
||||||
//
|
|
||||||
// $labels = array(
|
|
||||||
// 'name' => _x( 'Associats Tags', 'Taxonomy General Name', 'text_domain' ),
|
|
||||||
// 'singular_name' => _x( 'Associat Tag', 'Taxonomy Singular Name', 'text_domain' ),
|
|
||||||
// 'menu_name' => __( 'Associats Tags', 'text_domain' ),
|
|
||||||
// 'all_items' => __( 'All associat tags', 'text_domain' ),
|
|
||||||
// 'parent_item' => __( 'Parent associat tag', 'text_domain' ),
|
|
||||||
// 'parent_item_colon' => __( 'Parent associat tag:', 'text_domain' ),
|
|
||||||
// 'new_item_name' => __( 'New associat tag', 'text_domain' ),
|
|
||||||
// 'add_new_item' => __( 'Add New associat tag', 'text_domain' ),
|
|
||||||
// 'edit_item' => __( 'Edit associat tag', 'text_domain' ),
|
|
||||||
// 'update_item' => __( 'Update associat tag', 'text_domain' ),
|
|
||||||
// 'separate_items_with_commas' => __( 'Separate associat tag with commas', 'text_domain' ),
|
|
||||||
// 'search_items' => __( 'Search associat tags', 'text_domain' ),
|
|
||||||
// 'add_or_remove_items' => __( 'Add or remove associat tag', 'text_domain' ),
|
|
||||||
// 'choose_from_most_used' => __( 'Choose from the most used associat tags', 'text_domain' ),
|
|
||||||
// 'not_associat' => __( 'Associat tag Not Associat', 'text_domain' ),
|
|
||||||
// );
|
|
||||||
// $rewrite = array(
|
|
||||||
// 'slug' => 'associat-tag',
|
|
||||||
// // 'with_front' => false,
|
|
||||||
// );
|
|
||||||
// //$capabilities = array(
|
|
||||||
// // 'manage_terms' => 'Xarxaprod Manage associat Tag',
|
|
||||||
// // 'edit_terms' => 'Xarxaprod Edit associat Tag',
|
|
||||||
// // 'delete_terms' => 'Xarxaprod Delete associat Tag',
|
|
||||||
// // 'assign_terms' => 'Xarxaprod Assign associat Tag',
|
|
||||||
// // );
|
|
||||||
//
|
|
||||||
// $args = array(
|
|
||||||
// 'labels' => $labels,
|
|
||||||
// 'hierarchical' => false,
|
|
||||||
// 'public' => true,
|
|
||||||
// 'show_ui' => true,
|
|
||||||
// 'show_admin_column' => true,
|
|
||||||
// 'show_in_nav_menus' => true,
|
|
||||||
// 'show_tagcloud' => true,
|
|
||||||
// 'rewrite' => $rewrite,
|
|
||||||
// //'capabilities' => $capabilities,
|
|
||||||
// 'map_meta_cap' => true //neded to apply the new capabilities.
|
|
||||||
// );
|
|
||||||
// register_taxonomy( 'xarxaprod-associat-tag', array( 'xarxaprod-associat' ) , $args );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Hook into the 'init' action
|
|
||||||
//add_action( 'init', 'xarxaprod_wpplugin_associat_tag_register', 0 );
|
|
||||||
|
|
||||||
// changing the permalink
|
|
||||||
// https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post
|
|
||||||
// change in register_post_type the slug 'rewrite' to this
|
|
||||||
// $rewrite = array(
|
|
||||||
// 'slug' => 'associat/%xarxaprod-associat-category%',
|
|
||||||
// 'with_front' => true,
|
|
||||||
// 'hierarchical' => true,
|
|
||||||
// );
|
|
||||||
// uncomment below
|
|
||||||
//
|
|
||||||
// function xarxaprod_wpplugin_associat_and_category_permalink( $post_link, $id = 0 ){
|
|
||||||
// $post = get_post($id);
|
|
||||||
// if ( is_object( $post ) && $post->post_type == 'xarxaprod-associat' ){
|
|
||||||
// $terms = wp_get_object_terms( $post->ID, 'xarxaprod-associat-category' );
|
|
||||||
// if( $terms ){
|
|
||||||
// return str_replace( '%xarxaprod-associat-category%' , $terms[0]->slug , $post_link );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return $post_link;
|
|
||||||
// }
|
|
||||||
// add_filter( 'post_type_link', 'xarxaprod_wpplugin_associat_and_category_permalink', 1, 2 );
|
|
|
@ -1,241 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Custom post type Convos.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @link https://xarxaprod.cat
|
|
||||||
* @since 1.0.0
|
|
||||||
* @package xarxaprod-wp-plugin
|
|
||||||
* @subpackage xarxaprod-wp-plugin/includes
|
|
||||||
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
|
||||||
*
|
|
||||||
* @internal never define functions inside callbacks.
|
|
||||||
* these functions could be run multiple times; this would result in a fatal error.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start custom post types
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/
|
|
||||||
* https://developer.wordpress.org/reference/functions/register_post_type/
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Register Custom Post Type
|
|
||||||
if ( ! function_exists('xarxaprod_wpplugin_custom_post_convo_init') ){
|
|
||||||
function xarxaprod_wpplugin_custom_post_convo_init() {
|
|
||||||
|
|
||||||
$labels = array(
|
|
||||||
'name' => _x( 'Convos', 'Post Tipu General Name', 'text_domain' ),
|
|
||||||
'singular_name' => _x( 'Convo', 'Post Tipu Singular Name', 'text_domain' ),
|
|
||||||
'menu_name' => __( 'Convos', 'text_domain' ),
|
|
||||||
'parent_item_colon' => __( 'Convos mare/pare:', 'text_domain' ),
|
|
||||||
'all_items' => __( 'Totas las convos', 'text_domain' ),
|
|
||||||
'view_item' => __( 'Mostra la convo', 'text_domain' ),
|
|
||||||
'add_new_item' => __( 'Affegeix un convo', 'text_domain' ),
|
|
||||||
'add_new' => __( 'Affegeix convo', 'text_domain' ),
|
|
||||||
'edit_item' => __( 'Edita convo', 'text_domain' ),
|
|
||||||
'update_item' => __( 'Desa convo', 'text_domain' ),
|
|
||||||
'search_items' => __( 'Cerca convo', 'text_domain' ),
|
|
||||||
'not_convo' => __( 'No hem pogut trovar ningúna convo', 'text_domain' ),
|
|
||||||
'not_convo_in_trash' => __( 'No hem trovat cap convo a la brosa', 'text_domain' )
|
|
||||||
);
|
|
||||||
$rewrite = array(
|
|
||||||
'slug' => 'convos'
|
|
||||||
);
|
|
||||||
// https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375
|
|
||||||
// https://developer.wordpress.org/reference/functions/register_post_type/#capability_type
|
|
||||||
//$capabilities = array(
|
|
||||||
// 'read' => 'read_convo',
|
|
||||||
// 'publish_posts' => 'publish_convo',
|
|
||||||
// 'edit_posts' => 'edit_convo',
|
|
||||||
// 'edit_published_posts' => 'edit_published_convo',
|
|
||||||
// 'edit_others_posts' => 'edit_others_convo',
|
|
||||||
// 'delete_posts' => 'delete_convo',
|
|
||||||
// 'delete_published_posts' => 'delete_published_convo',
|
|
||||||
// 'delete_others_posts' => 'delete_others_convos',
|
|
||||||
// 'delete_private_posts' => 'delete_private_convos'
|
|
||||||
// );
|
|
||||||
$args = array(
|
|
||||||
'label' => __( 'xarxaprod-convo', 'text_domain' ),
|
|
||||||
'description' => __( 'Convos', 'text_domain' ),
|
|
||||||
'labels' => $labels,
|
|
||||||
//'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
|
||||||
'supports' => array( 'title', 'editor', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
|
||||||
// 'taxonomies' => array(
|
|
||||||
// 'xarxaprod-convo-category',
|
|
||||||
// 'xarxaprod-convo-tag'
|
|
||||||
// ),
|
|
||||||
'hierarchical' => true,
|
|
||||||
'public' => true,
|
|
||||||
'show_ui' => true,
|
|
||||||
'show_in_menu' => true,
|
|
||||||
'show_in_nav_menus' => true,
|
|
||||||
'show_in_admin_bar' => true,
|
|
||||||
'show_in_rest' => true,
|
|
||||||
'menu_position' => 5,
|
|
||||||
'menu_icon' => 'dashicons-calendar',
|
|
||||||
'can_export' => true,
|
|
||||||
'has_archive' => true,
|
|
||||||
'exclude_from_search' => false,
|
|
||||||
'publicly_queryable' => true,
|
|
||||||
'capability_type' => 'post',
|
|
||||||
'rewrite' => $rewrite,
|
|
||||||
//'capabilities' => $capabilities,
|
|
||||||
//'map_meta_cap' => true //neded to apply the new capabilities.
|
|
||||||
);
|
|
||||||
register_post_type( 'xarxaprod-convo', $args );
|
|
||||||
}
|
|
||||||
}// end function_exists xarxaprod_wpplugin_custom_post_convo_init
|
|
||||||
// Hook into the 'init' action
|
|
||||||
add_action( 'init', 'xarxaprod_wpplugin_custom_post_convo_init', 0 );
|
|
||||||
|
|
||||||
|
|
||||||
// flush rewrite and when changing theme or plugin
|
|
||||||
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
|
|
||||||
if ( ! function_exists( 'xarxaprod_convo_rewrite_flush') ){
|
|
||||||
function xarxaprod_convo_rewrite_flush() {
|
|
||||||
xarxaprod_wpplugin_custom_post_convo_init();
|
|
||||||
flush_rewrite_rules();
|
|
||||||
}
|
|
||||||
}// end function_exists xarxaprod_convo_rewrite_flush
|
|
||||||
add_action( 'after_switch_theme', 'xarxaprod_convo_rewrite_flush' );
|
|
||||||
|
|
||||||
// give capabilities once the custom post id activated
|
|
||||||
// function xarxaprod_wpplugin_add_caps() {
|
|
||||||
// gets the XX role
|
|
||||||
// $admins = get_role( '' );
|
|
||||||
// $admins->add_cap( );
|
|
||||||
// gets the administrator role
|
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
//add_action( 'admin_init', 'xarxaprod_wpplugin_add_caps');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start custom taxonomies
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/
|
|
||||||
* https://developer.wordpress.org/reference/functions/register_taxonomy/
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Register Custom Taxonomy Category for Convos
|
|
||||||
//function xarxaprod_wpplugin_convo_category_register() {
|
|
||||||
|
|
||||||
// $labels = array(
|
|
||||||
// 'name' => _x( 'Convos Tipus', 'Taxonomy General Name', 'text_domain' ),
|
|
||||||
// 'singular_name' => _x( 'Tipus d`convo', 'Taxonomy Singular Name', 'text_domain' ),
|
|
||||||
// 'menu_name' => __( 'Convos Tipus', 'text_domain' ),
|
|
||||||
// 'all_items' => __( 'All type convos', 'text_domain' ),
|
|
||||||
// 'parent_item' => __( 'Parent type convo', 'text_domain' ),
|
|
||||||
// 'parent_item_colon' => __( 'Parent type convo:', 'text_domain' ),
|
|
||||||
// 'new_item_name' => __( 'New type convo', 'text_domain' ),
|
|
||||||
// 'add_new_item' => __( 'Add New type convo', 'text_domain' ),
|
|
||||||
// 'edit_item' => __( 'Edit type convo', 'text_domain' ),
|
|
||||||
// 'update_item' => __( 'Update type of convo', 'text_domain' ),
|
|
||||||
// 'separate_items_with_commas' => __( 'Separate type convo with commas', 'text_domain' ),
|
|
||||||
// 'search_items' => __( 'Search type of convo', 'text_domain' ),
|
|
||||||
// 'add_or_remove_items' => __( 'Add or remove type of convo', 'text_domain' ),
|
|
||||||
// 'choose_from_most_used' => __( 'Choose from the most used type of convo', 'text_domain' ),
|
|
||||||
// 'not_convo' => __( 'Tipus d`convo Not Convo', 'text_domain' )
|
|
||||||
// );
|
|
||||||
// $rewrite = array(
|
|
||||||
// 'slug' => 'convo-tipus'
|
|
||||||
// );
|
|
||||||
// //$capabilities = array(
|
|
||||||
// // 'manage_terms' => 'Xarxaprod Manage convos Tipus',
|
|
||||||
// // 'edit_terms' => 'Xarxaprod Edit convo Tipus',
|
|
||||||
// // 'delete_terms' => 'Xarxaprod Delete convos Tipus',
|
|
||||||
// // 'assign_terms' => 'Xarxaprod Assign convos Tipus',
|
|
||||||
// // );
|
|
||||||
// $args = array(
|
|
||||||
// 'labels' => $labels,
|
|
||||||
// 'hierarchical' => true,
|
|
||||||
// 'public' => true,
|
|
||||||
// 'show_ui' => true,
|
|
||||||
// 'show_admin_column' => true,
|
|
||||||
// 'show_in_nav_menus' => true,
|
|
||||||
// 'show_tagcloud' => false,
|
|
||||||
// 'rewrite' => $rewrite,
|
|
||||||
// //'capabilities' => $capabilities,
|
|
||||||
// 'map_meta_cap' => true //neded to apply the new capabilities.
|
|
||||||
|
|
||||||
// );
|
|
||||||
// register_taxonomy( 'xarxaprod-convo-category', array( 'xarxaprod-convo' ) , $args );
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Hook into the 'init' action
|
|
||||||
//add_action( 'init', 'xarxaprod_wpplugin_convo_category_register', 0 );
|
|
||||||
|
|
||||||
// Register Custom Taxonomy Tag for Convos
|
|
||||||
// function xarxaprod_wpplugin_convo_tag_register() {
|
|
||||||
//
|
|
||||||
// $labels = array(
|
|
||||||
// 'name' => _x( 'Convos Tags', 'Taxonomy General Name', 'text_domain' ),
|
|
||||||
// 'singular_name' => _x( 'Convo Tag', 'Taxonomy Singular Name', 'text_domain' ),
|
|
||||||
// 'menu_name' => __( 'Convos Tags', 'text_domain' ),
|
|
||||||
// 'all_items' => __( 'All convos tags', 'text_domain' ),
|
|
||||||
// 'parent_item' => __( 'Parent convo tag', 'text_domain' ),
|
|
||||||
// 'parent_item_colon' => __( 'Parent convo tag:', 'text_domain' ),
|
|
||||||
// 'new_item_name' => __( 'New convo tag', 'text_domain' ),
|
|
||||||
// 'add_new_item' => __( 'Add New convo tag', 'text_domain' ),
|
|
||||||
// 'edit_item' => __( 'Edit convo tag', 'text_domain' ),
|
|
||||||
// 'update_item' => __( 'Update convo tag', 'text_domain' ),
|
|
||||||
// 'separate_items_with_commas' => __( 'Separate convo tag with commas', 'text_domain' ),
|
|
||||||
// 'search_items' => __( 'Search convo tags', 'text_domain' ),
|
|
||||||
// 'add_or_remove_items' => __( 'Add or remove convo tag', 'text_domain' ),
|
|
||||||
// 'choose_from_most_used' => __( 'Choose from the most used convo tags', 'text_domain' ),
|
|
||||||
// 'not_convo' => __( 'Convo tag Not Convo', 'text_domain' ),
|
|
||||||
// );
|
|
||||||
// $rewrite = array(
|
|
||||||
// 'slug' => 'convo-tag',
|
|
||||||
// // 'with_front' => false,
|
|
||||||
// );
|
|
||||||
// //$capabilities = array(
|
|
||||||
// // 'manage_terms' => 'Xarxaprod Manage convos Tag',
|
|
||||||
// // 'edit_terms' => 'Xarxaprod Edit convo Tag',
|
|
||||||
// // 'delete_terms' => 'Xarxaprod Delete convos Tag',
|
|
||||||
// // 'assign_terms' => 'Xarxaprod Assign convos Tag',
|
|
||||||
// // );
|
|
||||||
//
|
|
||||||
// $args = array(
|
|
||||||
// 'labels' => $labels,
|
|
||||||
// 'hierarchical' => false,
|
|
||||||
// 'public' => true,
|
|
||||||
// 'show_ui' => true,
|
|
||||||
// 'show_admin_column' => true,
|
|
||||||
// 'show_in_nav_menus' => true,
|
|
||||||
// 'show_tagcloud' => true,
|
|
||||||
// 'rewrite' => $rewrite,
|
|
||||||
// //'capabilities' => $capabilities,
|
|
||||||
// 'map_meta_cap' => true //neded to apply the new capabilities.
|
|
||||||
// );
|
|
||||||
// register_taxonomy( 'xarxaprod-convo-tag', array( 'xarxaprod-convo' ) , $args );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Hook into the 'init' action
|
|
||||||
//add_action( 'init', 'xarxaprod_wpplugin_convo_tag_register', 0 );
|
|
||||||
|
|
||||||
// changing the permalink
|
|
||||||
// https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post
|
|
||||||
// change in register_post_type the slug 'rewrite' to this
|
|
||||||
// $rewrite = array(
|
|
||||||
// 'slug' => 'convos/%xarxaprod-convo-category%',
|
|
||||||
// 'with_front' => true,
|
|
||||||
// 'hierarchical' => true,
|
|
||||||
// );
|
|
||||||
// uncomment below
|
|
||||||
//
|
|
||||||
// function xarxaprod_wpplugin_convo_and_category_permalink( $post_link, $id = 0 ){
|
|
||||||
// $post = get_post($id);
|
|
||||||
// if ( is_object( $post ) && $post->post_type == 'xarxaprod-convo' ){
|
|
||||||
// $terms = wp_get_object_terms( $post->ID, 'xarxaprod-convo-category' );
|
|
||||||
// if( $terms ){
|
|
||||||
// return str_replace( '%xarxaprod-convo-category%' , $terms[0]->slug , $post_link );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return $post_link;
|
|
||||||
// }
|
|
||||||
// add_filter( 'post_type_link', 'xarxaprod_wpplugin_convo_and_category_permalink', 1, 2 );
|
|
|
@ -67,20 +67,10 @@ include( XARXAPROD_WPPLUGIN_PATH . 'includes/stylesheet-admin.php');
|
||||||
//include( XARXAPROD_WPPLUGIN_PATH . 'includes/stylesheet-public.php');
|
//include( XARXAPROD_WPPLUGIN_PATH . 'includes/stylesheet-public.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// post type ajuts
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-ajuts.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-ajuts.php');
|
||||||
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-ajuts-filter.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-ajuts-filter.php');
|
||||||
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-ajuts-filter-function-frontend.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-ajuts-filter-function-frontend.php');
|
||||||
|
|
||||||
// post type convocatories
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-convos.php');
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter.php');
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter-function-frontend.php');
|
|
||||||
|
|
||||||
// post type associats
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-associats.php');
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-associats-filter.php');
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-associats-filter-function-frontend.php');
|
|
||||||
|
|
||||||
// plugin js scripts
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');
|
||||||
|
|
Loading…
Reference in New Issue