• Resolved thecorkboard

    (@thecorkboard)


    Context:
    Creating a template for a custom post type that lists scholarly publications. Two sections are listed: “published” and “accepted”. Each publication has a key (publication_status) with values of either “accepted” or “published”.

    Question:
    Using an if statement, I’d like to put the ones marked “published” under the published sub-heading and the ones marked “accepted” under the accepted sub-heading. I’m new to PHP in this area and if you have a quick sample of code I could follow, that’d be great. Also, if you have particular resource sites on if statements that you go to often.

    Thanks for any AND all assistance!
    ~Kyle~

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thecorkboard

    (@thecorkboard)

    This seems to be working for just one part of the publication details. I’ll see if I can’t use it to get me going for my original question:

    <?php if ( get_post_meta(get_the_id(), 'publication_online_access', true)): ?>
    		<h4 class="publication_online_access">Online Access:</h4>
    		<p><a href="<?php echo get_post_meta(get_the_id(), 'publication_online_access', true); ?>"><?php echo get_post_meta(get_the_id(), 'publication_online_access', true); ?></a></p>
    	<?php endif; ?>

    Thread Starter thecorkboard

    (@thecorkboard)

    I solved my own issue using get_posts for two different loops:

    <!-- IF status is "published" list here -->
    <?php
    $args = array( 'post_type' => 'publication', 'meta_value'=> 'published', 'orderby' => 'title' );
    $published_publications = get_posts( $args );
    echo '<h3>Published</h3>';
    foreach ($published_publications as $post) :  setup_postdata($post); ?>
    	<div class="publication">
    		<h4 class="publication_title"><?php single_post_title(); ?></h4>
    		<?php echo get_post_meta(get_the_id(), 'publication_apa_citation', true); ?>
    
    		<?php if ( get_post_meta(get_the_id(), 'publication_online_access', true)): ?>
    			<h4 class="publication_online_access">Online Access:</h4>
    			<p><a href="<?php echo get_post_meta(get_the_id(), 'publication_online_access', true); ?>"><?php echo get_post_meta(get_the_id(), 'publication_online_access', true); ?></a></p>
    		<?php endif; ?>
    
    		<?php if ( get_post_meta(get_the_id(), 'publication_abstract', true)): ?>
    			<h4 class="publication_abstract">Abstract:</h4>
    			<p><?php echo get_post_meta(get_the_id(), 'publication_abstract', true); ?></p>
    		<?php endif; ?>
    	</div><!-- .publication -->
    <?php endforeach; ?>
    
    <!-- IF status is "accepted" list here -->
    <?php
    $args = array( 'post_type' => 'publication', 'meta_value'=> 'accepted', 'orderby' => 'title' );
    $published_publications = get_posts( $args );
    echo '<h3>Accepted</h3>';
    foreach ($published_publications as $post) :  setup_postdata($post); ?>
    	<div class="publication">
    		<h4 class="publication_title"><?php single_post_title(); ?></h4>
    		<?php echo get_post_meta(get_the_id(), 'publication_apa_citation', true); ?>
    
    		<?php if ( get_post_meta(get_the_id(), 'publication_online_access', true)): ?>
    			<h4 class="publication_online_access">Online Access:</h4>
    			<p><a href="<?php echo get_post_meta(get_the_id(), 'publication_online_access', true); ?>"><?php echo get_post_meta(get_the_id(), 'publication_online_access', true); ?></a></p>
    		<?php endif; ?>
    
    		<?php if ( get_post_meta(get_the_id(), 'publication_abstract', true)): ?>
    			<h4 class="publication_abstract">Abstract:</h4>
    			<p><?php echo get_post_meta(get_the_id(), 'publication_abstract', true); ?></p>
    		<?php endif; ?>
    	</div><!-- .publication -->
    <?php endforeach; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘An If statement for a specific value’ is closed to new replies.