Support

Home Forums Event Espresso Premium Add a WordPress Category to a Single-Event

Add a WordPress Category to a Single-Event

Posted: April 17, 2017 at 9:07 am


crier-eventapp

April 17, 2017 at 9:07 am

How can I add a existing category to an Event/Event-Page?
I want to show only Posts of an specific category on the startpage and mix general news(teaser) from an page with events (teaser).


Josh

  • Support Staff

April 17, 2017 at 5:37 pm

Hi there,

You can use a plugin like this one:

https://wordpress.org/plugins/display-posts-shortcode/

to display a list of posts from a category on an event page (by using a shortcode).


crier-eventapp

April 30, 2017 at 12:00 pm

Hey Josh, thanks for your answer.
So it’s not possible to add the events to an Category?

I’ve used this funktion to add them to my Post-Overview:

// Event to Post
function add_espresso_events_to_posts( $WP_Query ) {
  if ( $WP_Query instanceof WP_Query && ( $WP_Query->is_feed || $WP_Query->is_posts_page  || ( $WP_Query->is_home && ! $WP_Query->is_page ) ||  ( isset( $WP_Query->query_vars['post_type'] ) && ( $WP_Query->query_vars['post_type'] == 'post' || is_array( $WP_Query->query_vars['post_type'] ) && in_array( 'post', $WP_Query->query_vars['post_type'] ) ) ) ) ) {
    //if post_types ARE present and 'post' is not in that array, then get out!
    if ( isset( $WP_Query->query_vars['post_type'] ) && $post_types = (array) $WP_Query->query_vars['post_type'] ) {
      if ( ! in_array( 'post', $post_types ) ) {
        return;
      }
    } else {
      $post_types = array( 'post' );
    }
    if ( ! in_array( 'espresso_events', $post_types )) {
      $post_types[] = 'espresso_events';
      $WP_Query->set( 'post_type', $post_types );
    }
    return;
  }
}
add_action( 'pre_get_posts', 'add_espresso_events_to_posts', 10 );

Is there no way to add a category to this Post?
Or do you have an other idea how I can delimit the Posts (without CSS – display:none;)


Josh

  • Support Staff

April 30, 2017 at 9:17 pm

I’m sorry I’m not 100% clear on what exactly you mean by “add a category to this Post”. Do you mean adding the built-in WordPress “category” taxonomy to events? If so, you can add the following code to your site into a functions plugin:

add_filter( 'FHEE__EE_Register_CPTs__get_CPTs__cpts', 'ee_modify_taxonomies_of_event_espresso_cpt' );
function ee_modify_taxonomies_of_event_espresso_cpt( $cpt_registry_array ) {
    if ( isset( $cpt_registry_array['espresso_events'] ) ) {
        $cpt_registry_array['espresso_events']['args']['taxonomies'] = array( 
            'espresso_event_categories', 
            'espresso_event_type', 
            'category'
        );
    }
    return $cpt_registry_array;
}


crier-eventapp

May 1, 2017 at 4:40 am

That’s great!
Now I can add a built in WordPress category to an event.
But do you have any ideas why its not shown by using this:

	<?php
		query_posts( array(
		'category_name'  => 'example-category',
		) );
	?>  

Do you understand what I want to do?


Josh

  • Support Staff

May 1, 2017 at 8:19 am

I do not understand, but you really should not use query_posts(). Here’s a link to the WP Codex that shows an example of how to query by a taxonomy term:

https://codex.wordpress.org/Taxonomies#Querying_by_taxonomy

The support post ‘Add a WordPress Category to a Single-Event’ 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