display all events with same post title in a different template

Home Forums Calendar Products Events Calendar PRO display all events with same post title in a different template

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #969288
    thomas
    Participant

    hi,

    i use a blog post with single.php
    i allready construct a custom event template named “dates.php” and put it into [my-theme]/tribe-events folder.

    how can i achieve the following task.
    1. get the post title, not hard: thats not hard it’s the.title()
    2. get events that have the same title as the post title
    3. output events with the dates.php template inside the single.php
    4. adjust the outputted date format
    5. put out the correct order (only upcoming events & starting with the closest in time)

    thanks for fast solution
    thomas

    #969339
    George
    Participant

    Hi Thomas,

    The full extent of your customization unfortunately is a bit outside the scope of the support we can provide, so we unfortunately won’t be able to write a complete solution for you here.

    The first complexity to wrestle with is the very premise of your customization – getting events that have the same title. There are functions within WordPress like get_page_by_title(), so you can check that out, but it would likely not work well in any capacity for getting multiple events by title. It seems like the best way to do that reliably would be to write custom SQL queries using $wpdb.

    As for displaying events in single.php with the date.php template, that should fortunately be quite simple – you can just the function tribe_get_template_part(), and reference the date.php file with a relative file path (explore views in the /views folder, like single-event.php, to see how this is done).

    When it comes to sorting the results by a certain order, this depends on how you retrieve the events to begin with. They should be sorted by date already in almost all the various options of retrieval already.

    I know there’s not much detail here, an I apologize for our limitations that lead to that, but hopefully my reply contains some useful information and you can start making some progress with your customization. If anything I mentioned is something you’re not familiar with, simply searching for more details about it online, or on specific sites like the WordPress codex (http://codex.wordpress.org), should help immensely.

    Best of luck with your customizations!
    George

    #969348
    thomas
    Participant

    hey george, okay i understand your point.
    is there a way i can read the tag of an event.

    this would be working too:
    get all events that have the tag “wein-tante”
    thanks and regards

    #969552
    George
    Participant

    Hey Thomas,

    You can get the tags of an event by deciding what taxonomy you want to list the terms of, and then using the WordPress function get_the_terms()https://codex.wordpress.org/Function_Reference/get_the_terms

    Pass the post ID of the Event for the $id parameter, and tribe_events_cat as taxonomy for Event Categories or post_tag for Tags.

    — George

    #969649
    thomas
    Participant

    hey george, i googled around and come up with this:

    <?php query_posts(array(
    'post_type' => 'tribe_events',
    'order'     => 'ASC',
    'tag'       => basename( get_permalink() )
    ));
    while (have_posts()) : the_post(); $event = get_post();
    echo "<br>";
    echo tribe_get_start_date( $event, $displayTime = false, $dateFormat = "l, j. F Y" );
    if ( -1 == $event->menu_order ) { echo " - bereits ausgebucht"; };
    endwhile; wp_reset_query(); ?>

    works quite well. only thing is i cannot search the post title – this seems to be a huge lack in wordpress itself. is there a workaround or solution for this?

    #969651
    thomas
    Participant

    my try is to use the search function in the query, because i read that by default the post title gets searched as well. somehow this is not working at all:

    <?php query_posts(array(
    'post_type' => 'tribe_events',
    'order'     => 'ASC',
    's'         => 'Das kleine Wein ABC'
    ));

    maybe you got something that solves the last issue here…

    #969768
    George
    Participant

    Hey Thomas,

    While we cannot help with custom code, even if we could this is unfortunately, as you said, an inherent limitation with WordPress itself. Searching by titles is tricky, the ‘s’ parameter for WP_Querys like you’re using in your last-posted example is a pretty good try at it, but writing custom Database queries is probably the best way to go.

    You can learn about querying for things with the WP Database here → https://codex.wordpress.org/Class_Reference/wpdb

    I’ll close up this particular thread for now since we cannot provide further support with the customization here, but if new questions or concerns arise drop by and open a new thread any time.

    Cheers!
    George

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘display all events with same post title in a different template’ is closed to new replies.