Support

Account

Forum Replies Created

  • This may be close, but i may not be understanding it. My main cpt is the event, so I thought that I would be querying that post. so say i wanted to see all the speakers (both normal and frontpage) from the most recent event…

    I was thinking something like this:

    $query = new WP_Query( 
    		array( 
    			'post_type' => 'events', 
    			'posts_per_page' => '1', 
    			'order' => 'DESC',
    		)
    	 );
            $count = $query->post_count;
            $i = 1;
    while ( $query->have_posts() ) : $query->the_post();
        $speakers = array_merge(
             get_field('relationship_1', false, false),
             get_field('relationship_2', false, false));
        if($speakers): 
           echo '<ul>';
    	foreach( $speakers as $speaker ):
                echo '<li>'.get_the_title($speaker -> ID).'</li>';
    	    $i++;	
    	endforeach;
    	 echo '</ul>';
    
    endif;
    endwhile;
    
    wp_reset_postdata();
    
    ?>

    does that make sense?

  • This reply has been marked as private.
  • Thanks for helping, with this. It didn’t work though. I’m not sure what the strolower is, but it looks to place everything in lowercase ( don’t need that). in any case it’s not affecting the order or changing case when i implement this code.

    I’m not sure that the title is right in the add_filter call.
    right now it’s name=session_speaker. should it be name=session?

    To make sure we’re on teh same page…
    CPT 1. (EVENT)

    session (repeater field)
    session_speaker (post object related to CPT SPEAKER)

    CPT 2. (SPEAKER)
    title (this is what i want to be sorted by.

    So when someone loads my event page and browses to the schedeule they will see a session that has several speakers. I want those items to sort by 2nd word in title of the SPEAKER posts that are showing up. If nothing else by ASC at minimum. Right now they are sorted by how we drag them in the page edit page when entering them (see image previously attached) I want to over-ride that so no matter how they are entered, they will present on front end in alpha ASC order.

  • is there any way to do with with repeater fields, so i could say load all the speakers who are on that forum post?

  • got it figured out. Thanks.

  • This reply has been marked as private.
  • i believe i figured it out.

    it works if i change the first line from:

    <?php if (get_sub_field('session-title')="TBA") {

    to

    <?php if (get_sub_field('session-title')=="TBA") {

  • Wow. Much simpler than I thought Thanks again!

  • John, you’ve been a great help. Just one last question and i believe this is done. how would i make it so that if there is more than 1 speaker it says “speakers” instead of just “speaker”? Can i count the array before the foreach?

    I tried inserting this:

    ...
                $sessionspeakers = get_sub_field('session_speaker');
                if ($sessionspeakers) {
                  $count = 0;
    	if($post_count=1){
    	echo 'Speaker '.$post_count.':<br>';
    	} else {
    	echo 'Speakers '.$post_count.':<br>';
    	}
    
                  foreach ($sessionspeakers as $speaker) {
    ...

    but it only returns 1 no matter how many speakers there are.

  • just out of curiosity though. what would be different if I only wanted there to be 1 selection? How would I do it with no loop?

  • ha, now i accidentally marked my OWN reply as the solution. JOHN did it though. HE solved this!

  • THIS is BRILLIANT!!!! Better than I was thinking is possible. Tnank you VERY much.

  • Hi John,
    I eventually do want there to be able to be more than 1 speaker in a session, i just couldn’t figure this part out to go to the next. I had thought to just make another repeater field called session_speaker2 or something, but if you know a better way, I would love to learn!

  • I have a field group called event. In that field group i have a repeater field called event_session. One of the fields in that repeater section is called session_speaker. It is a post_object related to a field in a different field group called speakers.

    I’m trying to create an event item where a user can choose who will be speaking at certain times in the events. These time slots i’m calling sessions.

    Here is a link to the fields in my event field group:
    http://awesomescreenshot.com/05756lqh29

    SO the line you mentioned above is just setting a variable to that subfield so i can pull content from the speakers field group.

  • Nothing changed. with those changes.

    I tried this too but it keeps repeating my “speakers is” over and over…not sure why?

    <?php
    
        $args = array(
            'post_type' => 'event'
        );
    
        $the_query = new WP_Query( $args );
    ?>
    
    <!-- WP_Query WordPress loop -->
    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
        <?php if(get_field('event_session')): ?>
            <?php while(has_sub_field('event_session')): ?>
                    <strong><?php the_sub_field('session_start'); ?>  </strong><?php the_sub_field('session_title'); ?><br>
    <!-- Start of speaker list -->
                    <div class="speaker_list">
                    <?php
                    $sessionspeakers = get_sub_field("session_speaker");
                    ?>    
                    <?php
                    if ( $sessionspeakers ) { 
                        
                        foreach ( $sessionspeakers as $sessionspeaker ) :
    
                            $speaker = get_post($sessionspeaker);
                            $speakerlink = get_permalink( $speaker->ID );
                            $speakerurltext = get_post_meta($speaker->ID, 'speakerurltext', $single = true); 
                            echo 'speaker is'. $speaker->post_title ; 
                        endforeach; 
                        
                    } ?>
                    </div><!-- End of speaker list -->
            <?php endwhile; ?>
        <?php endif; ?>
    
    <?php endwhile; else: ?>
    
        <!-- Displayed if no posts or pages are available -->
        <p>There are no posts or pages here!</p>
    
    <?php endif; ?>

    The result, under each event is this:

    8:00AM Registration & Breakfast
    speaker isChristian Kochspeaker isspeaker isspeaker isspeaker isspeaker isspeaker is2015speaker isspeaker isspeaker isspeaker is2015speaker isspeaker is2015speaker is2015speaker isspeaker isspeaker is2015speaker is2015speaker isspeaker is2015speaker isspeaker is2015speaker is2015speaker is

    Why does it keep repeating?

  • any chance for assistance? I appreciate it!

  • i know this is an older post but I can’t seem to get this worked out.
    I have a custom post type “event” that has a repeater field in it. One of the repeater sub fields is a relational post object field to another custom post type that i need pull data from a custom field.

    So here is what i have. Event has a field called event_session which is a repeater field. One of the sub-fields is called “session_speaker” it is a post object that is connected to my speaker custom postype.

    When someone creates a row from the repeater field in my event page they will choose a speaker. On the front end i want to pull that speakers company name and twitter link (both custom fields).

    Here is what i tried:

    <?php
    
        $args = array(
            'post_type' => 'event'
        );
    
        $the_query = new WP_Query( $args );
    ?>
    
    <!-- WP_Query WordPress loop -->
    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
        <?php if(get_field('event_session')): ?>
            <?php while(has_sub_field('event_session')): ?>
                    <strong><?php the_sub_field('session_start'); ?>  </strong><?php the_sub_field('session_title'); ?><br>
    <?php
    $speakers = get_sub_field("session_speaker");
    if ($speakers && count($speakers)>0)
    {
        foreach ($speakers as $speaker)
        {
            echo $speaker->ID; //$speaker is a post object//
        }        
    }
    ?>	
    
            <?php endwhile; ?>
        <?php endif; ?>
    
    <?php endwhile; else: ?>
    
        <!-- Displayed if no posts or pages are available -->
        <p>There are no posts or pages here!</p>
    
    <?php endif; ?>

    This shows nothing, but if i change the echo $speaker->ID to just echo $speaker, the array data does show up.

    I tried from above as well:

    <?php
    
        $args = array(
            'post_type' => 'event'
        );
    
        $the_query = new WP_Query( $args );
    ?>
    
    <!-- WP_Query WordPress loop -->
    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
        <?php if(get_field('event_session')): ?>
            <?php while(has_sub_field('event_session')): ?>
                    <strong><?php the_sub_field('session_start'); ?>  </strong><?php the_sub_field('session_title'); ?><br>
    
    <?php	$postObjects = get_sub_field('session_speaker');
    
    if($postObjects){
    foreach($postObjects as $post){
    setup_postdata($post);
    the_title();
    }
    wp_reset_postdata();
    }?>
    	
    	<?php echo $postObject->$post_title; ?>
    
            <?php endwhile; ?>
        <?php endif; ?>
    
    <?php endwhile; else: ?>
    
        <!-- Displayed if no posts or pages are available -->
        <p>There are no posts or pages here!</p>
    
    <?php endif; ?>	

    This shows the speaker title but even though I have 4 rows in my repeater field it will only show the first one.

  • I submitted a ticket thanks.

  • i have the newest version. They said “talk to plugin author” ha.

Viewing 21 posts - 26 through 46 (of 46 total)