Support

Home Forums Event Espresso Premium Adding tags and event category to CSV download

Adding tags and event category to CSV download

Posted: August 8, 2016 at 3:30 pm

Viewing 5 reply threads


Oguzhan Altun

August 8, 2016 at 3:30 pm

Hello,

Continuing from this thread:

I’d like to add the tags (which I use for language of the courses) and also the event category into the csv download.

For the tags, based on your guidance, I wrote this code, would that work?

add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_author_to_report', 10, 2);
function espresso_add_tag_to_report( $reg_csv_array, $reg_row ) {
	$event_id = $reg_row['Registration.EVT_ID'];
	$event = EEM_Event::instance()->get_one_by_ID( $event_id );
	if ( $event instanceof EE_Event ) {
		$posttags = get_the_tags();
		$count=0;
		if ($posttags) {
			foreach($posttags as $tag) {
    			$count++;
    			if (1 == $count) {
      				echo $tag->name;
    			}
  			}
		}
		
	return $reg_csv_array;
}

I would also like to add the event category, should I use this example?
https://developer.wordpress.org/reference/functions/get_the_category/


Josh

  • Support Staff

August 8, 2016 at 3:57 pm

What you have so far will not work because you’ll need to pass in the post ID (or in this case event ID) to the get_the_tags() function. e.g.
$posttags = get_the_tags( $event_id );

Also, the way you have the counter set up, it will show only one tag for the event. If you want all tags, you’ll remove the counter from the loop.

I would also like to add the event category, should I use this example?
https://developer.wordpress.org/reference/functions/get_the_category/

You’ll actually need to use get_the_terms() because event categories are a taxonomy term, which is very similar to a post category, but they’re not one and the same.


Oguzhan Altun

August 8, 2016 at 6:16 pm

Hi,

For the tags, I updated the code to the following but something is wrong, the report gets stuck at zero percent. Any ideas what’s wrong?

add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_tag_to_report', 10, 2);
function espresso_add_tag_to_report( $reg_csv_array, $reg_row ) {
	$event_id = $reg_row['Registration.EVT_ID'];
	$event = EEM_Event::instance()->get_one_by_ID( $event_id );
	if ( $event instanceof EE_Event ) {
		$posttags = get_the_tags( $event_id );
		$count=0;
		if ($posttags) {
			foreach($posttags as $tag) {
    			$count++;
    			if (1 == $count) {
      				echo $tag->name;
    			}
  			}
		}
	}		
	return $reg_csv_array;
}

For the category, how should I change the code then? I’m not really clear how to apply this example into the code to add just the category.


Josh

  • Support Staff

August 9, 2016 at 9:08 am

You need to clean up your code Oguzhan. First, you should not be echo’ing anything there. So this:

echo $tag->name;

needs to be something like this instead:

$reg_csv_array['Tag'] = $tag->name;

I mentioned this before, but it bears repeating: If you want to display all of the tags, you’ll need to remove the counter.

I’m not really clear how to apply this example into the code to add just the category.

You could also use https://developer.wordpress.org/reference/functions/get_the_term_list/


Oguzhan Altun

August 9, 2016 at 11:42 am

Hi there,

Thank you for your input. It worked with the new code – I have the tags displayed (left the counter on because I anyway only have one tag to represent the language the course is given).

The only strange result was that in the download, the tag data showed up under the “Transaction Promotions” heading (column AI), and it “pushed” the data of the Transaction Promotions to column AJ. I.e. it did not create a heading for itself.

For the category, I read the documentation of the get_the_term_list, but I have no idea how to apply to EE4. If it will be very difficult, i can survive without it.


Josh

  • Support Staff

August 9, 2016 at 12:02 pm

The only strange result was that in the download, the tag data showed up under the “Transaction Promotions” heading (column AI), and it “pushed” the data of the Transaction Promotions to column AJ. I.e. it did not create a heading for itself.

You might try removing the counter first to see if that makes a difference.

Viewing 5 reply threads

The support post ‘Adding tags and event category to CSV download’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso