• I am really not a programmer but got this far by searching the forum.

    I am using the Types plugin, to create custom post types and custom fields.

    Three things I would like to do:
    – don’t display tag if it’s empty
    – sort the posts alfabetical
    – if custom field “links-notes” is empty don’t display

    <?php
    	$tags = get_tags();
    	foreach ( $tags as $tag ) {
    	echo '<div class="row">';
    	echo '<h3>' .$tag->name. '</h3>';
    	$tag_query = new WP_Query( array(
    		'post_type' => array('links'),
    		'tag_id' => $tag->term_id,
    		'posts_per_page' => -1,
    		'no_found_rows' => true,
    		) );
    	while ( $tag_query->have_posts() ) : $tag_query->the_post(); ?>
    		<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
    			<p><a href="<?php echo types_render_field("links-url", array("output"=>"raw")); ?>"><?php the_title(); ?></a> (<?php echo types_render_field("links-notes", array("output"=>"HTML")); ?>)</p>
    		</div><!-- .col -->
    <?php endwhile;
    	echo '</div><!-- .row -->';
    	wp_reset_postdata(); } ?>

    Please remember that I am not a programmer so please be very specific ??

    Any help is very much appreciated!

Viewing 1 replies (of 1 total)
  • Thread Starter voldby

    (@voldby)

    I have solved the second and third things on my list.

    Only the first I don’t know how to solve:
    – don’t display tag if no post exist

    <?php
    	$tags = get_tags();
    	foreach ( $tags as $tag ) {
    	echo '<div class="row">';
    	echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><h3>' .$tag->name. '</h3></div><!-- .col -->';
    	$tag_query = new WP_Query( array(
    		'post_type' => array('links'),
    		'tag_id' => $tag->term_id,
    		'posts_per_page' => -1,
    		'no_found_rows' => true,
    		) );
    	$posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1'); while ( $tag_query->have_posts() ) : $tag_query->the_post(); ?>
    		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    			<p><a href="<?php echo types_render_field("links-url", array("output"=>"raw")); ?>"><?php the_title(); ?></a>
    				<?php if(types_render_field('links-notes', array('raw'=>'true'))){?>
    					(<?php echo types_render_field("links-notes", array("output"=>"HTML")); ?>)
    				<?php }?>
    			</p>
    		</div><!-- .col -->
    <?php endwhile;
    	echo '</div><!-- .row -->';
    	wp_reset_postdata(); } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘don't display if empty sort alfabetical’ is closed to new replies.