Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Gram3000

    (@gram3000)

    Thanks YOU!

    I thought that the if statement was always true. Due to my lack in knowledge I didn’t realize I could call the field label (if that’s it name) with the function. I’m learning, which is good.

    @david I had been using the function to cut down on repeat code with lots custom field types. I started using a plugin to handle custom fields to clean up the back end. Now the only field left is video. I could drop the function completely.

    Thanks you very much gentle men!

    Thread Starter Gram3000

    (@gram3000)

    I found almost prefect awesome solution here

    I have the term posts being displayed.

    place this in functions.php

    function get_posts_related_by_taxonomy($post_id,$taxonomy,$args=array()) {
    		  $query = new WP_Query();
    		  $terms = wp_get_object_terms($post_id,$taxonomy);
    		  if (count($terms)) {
    		    // Assumes only one term for per post in this taxonomy
    		    $post_ids = get_objects_in_term($terms[0]->term_id,$taxonomy);
    		    $post = get_post($post_id);
    		    $args = wp_parse_args($args,array(
    		      'post_type' => $post->post_type, // The assumes the post types match
    		      'post__in' => $post_ids,
    		      'post__not_in' => $post->ID,
    		      'taxonomy' => $taxonomy,
    		      'term' => $terms[0]->slug,
    		    ));
    		    $query = new WP_Query($args);
    		  }
    		  return $query;
    		}

    and this in the template

    $organiziation = get_posts_related_by_taxonomy($post->ID,'organizations');?>			
    
    <?php while ($organiziation->have_posts()): $organiziation->the_post();
    
    if( $post->ID == $do_not_duplicate ) continue;

    I’m learning! just. Thanks so much for taking time out of your day to help me.

    Any ideas on how to limit which category is displayed?

    Thread Starter Gram3000

    (@gram3000)

    Tried removing the ‘terms’ from the query array and then replaced the ‘the_permalink’ with ‘get_term_link’. For a moment as I was going through the steps I thought maybe it would work. It ended up removing all the post data.

    I feel like I’m close. I wish that I could get a variable from the ‘the_terms’ function and then pass it into the query to replace ‘x’

    <?php the_terms( $post->ID, 'organizations', '', '', '' ); ?>

    This line the browser return my term ‘x’ but how can I use it with my query? What about this?

    $var = the_terms( $post->ID, 'organizations', '', '', '' );

    and then place it in the query.

    'tax_query' => array( array(
          'taxonomy' => 'organizations',
          'field' => 'slug',
          'terms' =>  '$var' ))
    )); ?>
    Thread Starter Gram3000

    (@gram3000)

    Thanks for your reply,

    I’d like to display more than the link for the post. I have the ‘the_title()’ as a place holder for testing to see if the query is working.

    I’ll be displaying custom fields, the_excerpt, the_title. I haven’t understood that I could display post data from ‘get_term_link’ is that possible? I’m learning ??

Viewing 4 replies - 1 through 4 (of 4 total)