Skip to content

Instantly share code, notes, and snippets.

@icle-anayltics
Created May 13, 2019 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icle-anayltics/a0be8f5bb12c081a8524ce121af91695 to your computer and use it in GitHub Desktop.
Save icle-anayltics/a0be8f5bb12c081a8524ce121af91695 to your computer and use it in GitHub Desktop.
Event Espresso custom csv export with ACF columns
<?php
/*
Plugin Name: Site plugin for iclega-attend.org
Description: Site specific code for iclega-attend.org
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_meta_value_csv', 10, 2);
function espresso_add_meta_value_csv( $reg_csv_array, $reg_row ) {
// get the event's ID
$event_id = $reg_row[ 'Registration.EVT_ID' ];
// example of getting the post meta
$materials_link = get_post_meta( $event_id, 'materials_link', true );
if ( $materials_link != '' ) {
$reg_csv_array[ 'materials_link' ] = $materials_link;
}
// example of getting the post meta
$fourd_program_number = get_post_meta( $event_id, 'fourd_program_number', true );
if ( $fourd_program_number != '' ) {
$reg_csv_array[ 'fourd_program_number' ] = $fourd_program_number;
}
// example of getting the post meta
$cle_value_main = get_post_meta( $event_id, 'cle_value_main', true );
if ( $cle_value_main != '' ) {
$reg_csv_array[ 'cle_value_main' ] = $cle_value_main;
}
// example of getting the post meta
$cle_value_ethics = get_post_meta( $event_id, 'cle_value_ethics', true );
if ( $cle_value_ethics != '' ) {
$reg_csv_array[ 'cle_value_ethics' ] = $cle_value_ethics;
}
// example of getting the post meta
$cle_value_professionalism = get_post_meta( $event_id, 'cle_value_professionalism', true );
if ( $cle_value_professionalism != '' ) {
$reg_csv_array[ 'cle_value_professionalism' ] = $cle_value_professionalism;
}
// example of getting the post meta
$cle_value_trial_practice = get_post_meta( $event_id, 'cle_value_trial_practice', true );
if ( $cle_value_trial_practice != '' ) {
$reg_csv_array[ 'cle_value_trial_practice' ] = $cle_value_trial_practice;
}
return $reg_csv_array;
}
/* add advanced custom fields to site search */
/**
* Extend WordPress search to include custom fields
*
* https://adambalee.com
*/
/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'cf_search_join' );
/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*/
function cf_search_where( $where ) {
global $pagenow, $wpdb;
if ( is_search() ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'cf_search_where' );
/**
* Prevent duplicates
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*/
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );
/* Stop Adding Functions */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment