added custom convo and its filters

This commit is contained in:
jorge-vitrubio 2024-01-27 18:31:59 +01:00
parent 4cd884163b
commit bd29254d9a
8 changed files with 125 additions and 123 deletions

View File

@ -15,10 +15,3 @@
* 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;
}
*/

View File

@ -42,7 +42,7 @@ if( ! function_exists( 'xarxaprod_ajuts_filters_form') ) {
if( $fields ) {
// check for values from meta fields db in url
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ) {
foreach( $GLOBALS['my_query_filters_ajut'] as $key => $fieldname ) {
// check for values in url and get value if available
if( isset($_GET[ $fieldname ]) ) {

View File

@ -14,21 +14,21 @@
// define the filter fields
// array of filters (field key => field name)
$GLOBALS['my_query_filters'] = array(
$GLOBALS['my_query_filters_ajut'] = array(
'fundtarget' => 'os_fund_target',
'fundsource' => 'os_fund_source',
'fundfield' => 'os_fund_field'
);
$GLOBALS['my_query_filters_dates'] = array(
$GLOBALS['my_query_filters_ajut_dates'] = array(
'fundapplybegin' => 'os_fund_apply_begin',
'fundapplyend' => 'os_fund_apply_end'
//'fundcall' => 'os_fund_call',
);
// action
add_action('pre_get_posts', 'my_pre_get_posts',10,1);
function my_pre_get_posts( $query ) {
add_action('pre_get_posts', 'my_pre_get_posts_ajuts',10,1);
if ( ! function_exists('my_pre_get_posts_ajuts') ){
function my_pre_get_posts_ajuts( $query ) {
// bail early if is in admin
if( is_admin() ) { return; }
@ -40,7 +40,7 @@ function my_pre_get_posts( $query ) {
// loop over filters
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname)
foreach( $GLOBALS['my_query_filters_ajut'] as $key => $fieldname)
{
// continue if not found in url
if( empty($_GET[ $fieldname ]) ) { continue; }
@ -78,4 +78,5 @@ function my_pre_get_posts( $query ) {
//always return
return;
}
}

View File

@ -25,7 +25,7 @@ if( ! function_exists( 'xarxaprod_convos_filters_form') ) {
<div id="archive-filters" class="xarxaprod-filters">
<?php
// output all possible values of a checkbox
$groupkey = "group_XXXXXX"; // write here the key for the group of fields from acf
$groupkey = "group_65abb25b84079"; // write here the key for the group of fields from acf
if( $groupkey ) {
?>
<?php // start the form ?>
@ -42,7 +42,7 @@ if( ! function_exists( 'xarxaprod_convos_filters_form') ) {
if( $fields ) {
// check for values from meta fields db in url
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ) {
foreach( $GLOBALS['my_query_filters_convo'] as $key => $fieldname ) {
// check for values in url and get value if available
if( isset($_GET[ $fieldname ]) ) {

View File

@ -14,21 +14,23 @@
// define the filter fields
// array of filters (field key => field name)
$GLOBALS['my_query_filters'] = array(
'calltarget' => 'os_call_target',
'callsource' => 'os_call_source',
'callfield' => 'os_call_field'
$GLOBALS['my_query_filters_convo'] = array(
'convofield' => 'os_convo_field', //disciplines
'convoterritory' => 'os_convo_territory', //territori
'convoservice' => 'os_convo_service', //serveis
'convocenter' => 'os_convo_center' //centre
);
$GLOBALS['my_query_filters_dates'] = array(
'callapplybegin' => 'os_call_apply_begin',
'callapplyend' => 'os_call_apply_end'
//'callcall' => 'os_call_call',
$GLOBALS['my_query_filters_convo_dates'] = array(
'convoapplybegin' => 'os_convo_apply_begin',
'convoapplyend' => 'os_convo_apply_end'
//'convocall' => 'os_convo_call',
);
// action
add_action('pre_get_posts', 'my_pre_get_posts',10,1);
function my_pre_get_posts( $query ) {
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; }
@ -40,7 +42,7 @@ function my_pre_get_posts( $query ) {
// loop over filters
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname)
foreach( $GLOBALS['my_query_filters_convo'] as $key => $fieldname)
{
// continue if not found in url
if( empty($_GET[ $fieldname ]) ) { continue; }
@ -51,12 +53,12 @@ function my_pre_get_posts( $query ) {
$meta_query[] = array('relation' => 'OR');
// get the values for this filter
// eg: http://domain.tdl/convo/?os_call_target=autonoma,entitat-publica
// eg: http://domain.tdl/convo/?os_convo_target=autonoma,entitat-publica
$filtervalues= explode(',', $_GET[ $fieldname ]);
// loop retreived values from checkboxes and filter them with REGEXP
// http://domain.tdl/convo/?os_call_target=autonoma&os_call_field=circi
// http://domain.tdl/convo/?os_call_target=autonoma,entitat-publica&os_call_field=dansa
// http://domain.tdl/convo/?os_convo_target=autonoma&os_convo_field=circi
// http://domain.tdl/convo/?os_convo_target=autonoma,entitat-publica&os_convo_field=dansa
foreach( $filtervalues as $filteredvalue )
{
// they are array based fields
@ -78,4 +80,5 @@ function my_pre_get_posts( $query ) {
//always return
return;
}
}

View File

@ -22,7 +22,8 @@
// Register Custom Post Type
function xarxaprod_wpplugin_custom_post_ajut_init() {
if ( ! function_exists('xarxaprod_wpplugin_custom_post_ajut_init') ){
function xarxaprod_wpplugin_custom_post_ajut_init() {
$labels = array(
'name' => _x( 'Ajuts', 'Post Tipu General Name', 'text_domain' ),
@ -84,17 +85,20 @@
//'map_meta_cap' => true //neded to apply the new capabilities.
);
register_post_type( 'xarxaprod-ajut', $args );
}
}
}// end function_exists xarxaprod_wpplugin_custom_post_ajut_init
// Hook into the 'init' action
add_action( 'init', 'xarxaprod_wpplugin_custom_post_ajut_init', 0 );
// 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() {
xarxaprod_wpplugin_custom_post_ajut_init();
flush_rewrite_rules();
}
}// end function_exists xarxaprod_ajut_rewrite_flush
add_action( 'after_switch_theme', 'xarxaprod_ajut_rewrite_flush' );
// give capabilities once the custom post id activated

View File

@ -1,6 +1,6 @@
<?php
/**
* Custom post type Convocatories.
* Custom post type Convos.
*
*
* @link https://xarxaprod.cat
@ -22,42 +22,43 @@
// Register Custom Post Type
function xarxaprod_wpplugin_custom_post_convocatoria_init() {
if ( ! function_exists('xarxaprod_wpplugin_custom_post_convo_init') ){
function xarxaprod_wpplugin_custom_post_convo_init() {
$labels = array(
'name' => _x( 'Convocatories', 'Post Tipu General Name', 'text_domain' ),
'singular_name' => _x( 'Convocatoria', 'Post Tipu Singular Name', 'text_domain' ),
'menu_name' => __( 'Convocatories', 'text_domain' ),
'parent_item_colon' => __( 'Convocatories mare/pare:', 'text_domain' ),
'all_items' => __( 'Totas las convocatories', 'text_domain' ),
'view_item' => __( 'Mostra la convocatoria', 'text_domain' ),
'add_new_item' => __( 'Affegeix una convocatoria', 'text_domain' ),
'add_new' => __( 'Affegeix convocatoria', 'text_domain' ),
'edit_item' => __( 'Edita convocatoria', 'text_domain' ),
'update_item' => __( 'Desa convocatoria', 'text_domain' ),
'search_items' => __( 'Cerca convocatoria', 'text_domain' ),
'not_convocatoria' => __( 'No hem pogut trovar ningún convocatoria', 'text_domain' ),
'not_convocatoria_in_trash' => __( 'No hem trovat cap convocatoria a la brosa', 'text_domain' )
'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' => 'convocatories'
'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_convocatoria',
// 'publish_posts' => 'publish_convocatoria',
// 'edit_posts' => 'edit_convocatoria',
// 'edit_published_posts' => 'edit_published_convocatoria',
// 'edit_others_posts' => 'edit_others_convocatoria',
// 'delete_posts' => 'delete_convocatoria',
// 'delete_published_posts' => 'delete_published_convocatoria',
// 'delete_others_posts' => 'delete_others_convocatories',
// 'delete_private_posts' => 'delete_private_convocatories'
// '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' => __( 'Convocatories', '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' ),
@ -72,8 +73,8 @@
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_rest' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-calendar', //https://developer.wordpress.org/resource/dashicons/#calendar
'menu_position' => 5,
'menu_icon' => 'dashicons-calendar',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
@ -84,18 +85,21 @@
//'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_convocatoria_init', 0 );
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
function xarxaprod_convocatoria_rewrite_flush() {
xarxaprod_wpplugin_custom_post_convocatoria_init();
// 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();
}
add_action( 'after_switch_theme', 'xarxaprod_convocatoria_rewrite_flush' );
}// 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() {
@ -117,34 +121,34 @@
* https://developer.wordpress.org/reference/functions/register_taxonomy/
*/
// Register Custom Taxonomy Category for Convocatories
//function xarxaprod_wpplugin_convocatoria_category_register() {
// Register Custom Taxonomy Category for Convos
//function xarxaprod_wpplugin_convo_category_register() {
// $labels = array(
// 'name' => _x( 'Convocatories Tipus', 'Taxonomy General Name', 'text_domain' ),
// 'singular_name' => _x( 'Tipus d`convocatoria', 'Taxonomy Singular Name', 'text_domain' ),
// 'menu_name' => __( 'Convocatories Tipus', 'text_domain' ),
// 'all_items' => __( 'All type convocatories', 'text_domain' ),
// 'parent_item' => __( 'Parent type convocatoria', 'text_domain' ),
// 'parent_item_colon' => __( 'Parent type convocatoria:', 'text_domain' ),
// 'new_item_name' => __( 'New type convocatoria', 'text_domain' ),
// 'add_new_item' => __( 'Add New type convocatoria', 'text_domain' ),
// 'edit_item' => __( 'Edit type convocatoria', 'text_domain' ),
// 'update_item' => __( 'Update type of convocatoria', 'text_domain' ),
// 'separate_items_with_commas' => __( 'Separate type convocatoria with commas', 'text_domain' ),
// 'search_items' => __( 'Search type of convocatoria', 'text_domain' ),
// 'add_or_remove_items' => __( 'Add or remove type of convocatoria', 'text_domain' ),
// 'choose_from_most_used' => __( 'Choose from the most used type of convocatoria', 'text_domain' ),
// 'not_convocatoria' => __( 'Tipus d`convocatoria Not Convocatoria', 'text_domain' )
// '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' => 'convocatoria-tipus'
// 'slug' => 'convo-tipus'
// );
// //$capabilities = array(
// // 'manage_terms' => 'Xarxaprod Manage convocatories Tipus',
// // 'edit_terms' => 'Xarxaprod Edit convocatoria Tipus',
// // 'delete_terms' => 'Xarxaprod Delete convocatories Tipus',
// // 'assign_terms' => 'Xarxaprod Assign convocatories Tipus',
// // '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,
@ -163,37 +167,37 @@
//}
// Hook into the 'init' action
//add_action( 'init', 'xarxaprod_wpplugin_convocatoria_category_register', 0 );
//add_action( 'init', 'xarxaprod_wpplugin_convo_category_register', 0 );
// Register Custom Taxonomy Tag for Convocatories
// function xarxaprod_wpplugin_convocatoria_tag_register() {
// Register Custom Taxonomy Tag for Convos
// function xarxaprod_wpplugin_convo_tag_register() {
//
// $labels = array(
// 'name' => _x( 'Convocatories Tags', 'Taxonomy General Name', 'text_domain' ),
// 'singular_name' => _x( 'Convocatoria Tag', 'Taxonomy Singular Name', 'text_domain' ),
// 'menu_name' => __( 'Convocatories Tags', 'text_domain' ),
// 'all_items' => __( 'All convocatories tags', 'text_domain' ),
// 'parent_item' => __( 'Parent convocatoria tag', 'text_domain' ),
// 'parent_item_colon' => __( 'Parent convocatoria tag:', 'text_domain' ),
// 'new_item_name' => __( 'New convocatoria tag', 'text_domain' ),
// 'add_new_item' => __( 'Add New convocatoria tag', 'text_domain' ),
// 'edit_item' => __( 'Edit convocatoria tag', 'text_domain' ),
// 'update_item' => __( 'Update convocatoria tag', 'text_domain' ),
// 'separate_items_with_commas' => __( 'Separate convocatoria tag with commas', 'text_domain' ),
// 'search_items' => __( 'Search convocatoria tags', 'text_domain' ),
// 'add_or_remove_items' => __( 'Add or remove convocatoria tag', 'text_domain' ),
// 'choose_from_most_used' => __( 'Choose from the most used convocatoria tags', 'text_domain' ),
// 'not_convocatoria' => __( 'Convocatoria tag Not Convocatoria', 'text_domain' ),
// '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' => 'convocatoria-tag',
// 'slug' => 'convo-tag',
// // 'with_front' => false,
// );
// //$capabilities = array(
// // 'manage_terms' => 'Xarxaprod Manage convocatories Tag',
// // 'edit_terms' => 'Xarxaprod Edit convocatoria Tag',
// // 'delete_terms' => 'Xarxaprod Delete convocatories Tag',
// // 'assign_terms' => 'Xarxaprod Assign convocatories Tag',
// // '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(
@ -212,19 +216,19 @@
// }
// Hook into the 'init' action
//add_action( 'init', 'xarxaprod_wpplugin_convocatoria_tag_register', 0 );
//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' => 'convocatories/%xarxaprod-convo-category%',
// 'slug' => 'convos/%xarxaprod-convo-category%',
// 'with_front' => true,
// 'hierarchical' => true,
// );
// uncomment below
//
// function xarxaprod_wpplugin_convocatoria_and_category_permalink( $post_link, $id = 0 ){
// 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' );
@ -234,4 +238,4 @@
// }
// return $post_link;
// }
// add_filter( 'post_type_link', 'xarxaprod_wpplugin_convocatoria_and_category_permalink', 1, 2 );
// add_filter( 'post_type_link', 'xarxaprod_wpplugin_convo_and_category_permalink', 1, 2 );

View File

@ -69,16 +69,13 @@ include( XARXAPROD_WPPLUGIN_PATH . 'includes/stylesheet-admin.php');
// post type ajuts
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-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');
//include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter.php');
//
//include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter-function-frontend.php');
// plugin js scripts
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');