• since i know you guys are all experts and all heres what i got.
    i have a custom taxonomy inside a custom post type
    there is a page that loops through and calls all the custom post types, and displays them
    then at the top there is a dropdown that needs to list all the taxonomies for those custom post types

    i have the page correctly displaying them, but the problem is the dropdown displays duplicated items. code below, the first is the code displaying now. the second is what i suggest but isn’t working

    ================ ORIGIONAL ======================

    <?php
    /**
    Template Name: Our Work Page
     */
    ?>
    
    <?php get_header(); ?>
    
    		<div id="pagePost">
    		<form method="post" id="clientform" action="" onsubmit="return getURL(this.url.value)">
    		<select name="url" id="client">
    	  		<option selected="selected">By Client</option>
    	 <?php
        $args=array(
    
          'post_type' => 'our_work',
          'post_status' => 'publish',
    	  'order' => 'ASC',
          'posts_per_page' => -1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) { ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <?php $text = trim(get_the_term_list( $post->ID, 'client_name')); ?>
    			<option value="<?php bloginfo('url'); echo "/client_name/"; echo $text; ?>"><?php echo $text;?></option>
    	<?php endwhile; } wp_reset_query(); ?>
    
      </select>
    <input type="submit" id="clientsubmit" value="Search" />
    </form>
        <?php query_posts('post_type=our_work&posts_per_page=12&orderby=rand'); // call random blog post ?>
    	<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    		<div class="grid_5a ourWorkImgWidth">
            <a href="<?php the_permalink(); ?>"><?php echo the_post_thumbnail(array(200,200,false)); ?></a>
    	    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            </div>
    
    		<?php endwhile; endif; wp_reset_query();?>
    
            </div> <!-- end of pagePost ID -->
    
    <?php get_footer(); ?>

    ============ what im tryn =============

    <?php
    /**
    Template Name: Our Work Page
     */
    ?>
    
    <?php get_header(); ?>
    
    		<div id="pagePost">
    		<form method="post" id="clientform" action="" onsubmit="return getURL(this.url.value)">
    		<select name="url" id="client">
    	  		<option selected="selected">By Client</option>
    	 <?php
        $args=array(
    
          'post_type' => 'our_work',
          'post_status' => 'publish',
    	  'order' => 'ASC',
          'posts_per_page' => -1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
    	$counter = 0;
        if( $my_query->have_posts() ) { ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <?php $termArray[] = array (trim(get_the_term_list( $post->ID, 'client_name'))) ?>
        <?php // $text = trim(get_the_term_list( $post->ID, 'client_name')); ?>
    
    	<?php endwhile; } wp_reset_query(); ?>
        <?php for ($i = 0; $i < $termArray.count; $i++ ) {
    		$tempArrayValueA = $termArray[$i];
    
    			for ($j = 0; $j < $tempArray.count; $j++) {
    				$tempArrayValueB = $termArray[$j];
    				$counter++;
    				if ($tempArrayValueA == $tempArrayValueB) {
    					if ($counter <= 2) {
    					echo $counter;
    					unset($termArray[$i]);
    					$termArray = array_values($termArray[]);
    					}
    				}else {  ?>
            			<option value="<?php bloginfo('url'); echo "/client_name/"; echo $termArray[i]; ?>"><?php echo $termArray[i];?></option>
    			<?php } // end of if
    			$counter = 0; // reset counter to 0 for each position in the orgiional array
    			} // end of for
    
    	} ?>
    
      </select>
    <input type="submit" id="clientsubmit" value="Search" />
    </form>
        <?php query_posts('post_type=our_work&posts_per_page=12&orderby=rand'); // call random blog post ?>
    	<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    		<div class="grid_5a ourWorkImgWidth">
            <a href="<?php the_permalink(); ?>"><?php echo the_post_thumbnail(array(200,200,false)); ?></a>
    	    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            </div>
    
    		<?php endwhile; endif; wp_reset_query();?>
    
            </div> <!-- end of pagePost ID -->
    
    <?php get_footer(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter i_know_god

    (@i_know_god)

    you can see the current code at https://magicvideo.com/cms/work/

    Thread Starter i_know_god

    (@i_know_god)

    made some code adjustments and fixes, but unless i put the array inside the loop i get nothing but the first value, any way to get the array out of the loop?

    <?php
    /**
    Template Name: Our Work Page
     */
    ?>
    
    <?php get_header(); ?>
    
    		<div id="pagePost">
    		<form method="post" id="clientform" action="" onsubmit="return getURL(this.url.value)">
    		<select name="url" id="client">
    	  		<option selected="selected">By Client</option>
    	 <?php
        $args=array(
    
          'post_type' => 'our_work',
          'post_status' => 'publish',
    	  'order' => 'ASC',
          'posts_per_page' => -1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
    	$counter = 0;
        if( $my_query->have_posts() ) { ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <?php $termArray[] = array (trim(get_the_term_list( $post->ID, 'client_name'))) ?>
        <?php // $text = trim(get_the_term_list( $post->ID, 'client_name')); ?>
    	<?php for ($i = 0; $i <= $termArray.count; $i++ ) {
    		$tempArrayValueA = $termArray[$i];
    
    			for ($j = 0; $j <= $tempArray.count; $j++) {
    				$tempArrayValueB = $termArray[$j];
    				$counter++;
    				if ($tempArrayValueA == $tempArrayValueB) {
    					if ($counter >= 2) {
    					echo $counter;
    					unset($termArray[$j]);
    					$termArray = array_values($termArray);
    					}else { ?>
    						<option value="<?php bloginfo('url'); echo "/client_name/"; echo $termArray[$j]; ?>"><?php echo $termArray[$j]; ?></option>
    				<?php }
    				}else {  ?>
            			<option value="<?php bloginfo('url'); echo "/client_name/"; echo $termArray[$j]; ?>"><?php echo $termArray[$j]; ?></option>
    			<?php } // end of if
    
    			} // end of for
    	$counter = 0; // reset counter to 0 for each position in the orgiional array
    	} ?>
    	<?php endwhile; } wp_reset_query(); ?>
    
      </select>
    <input type="submit" id="clientsubmit" value="Search" />
    </form>
        <?php query_posts('post_type=our_work&posts_per_page=12&orderby=rand'); // call random blog post ?>
    	<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    		<div class="grid_5a ourWorkImgWidth">
            <a href="<?php the_permalink(); ?>"><?php echo the_post_thumbnail(array(200,200,false)); ?></a>
    	    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            </div>
    
    		<?php endwhile; endif; wp_reset_query();?>
    
            </div> <!-- end of pagePost ID -->
    
    <?php get_footer(); ?>
    Thread Starter i_know_god

    (@i_know_god)

    reworked the code, and it looks nicer but has the same effect, 1 it doesnt remove the douplicates, and 2 i cant get it to display anything but “array” now

    i think its a scope issue

    <form method="post" id="clientform" action="" onsubmit="return getURL(this.url.value)">
    		<select name="url" id="client">
    	  		<option selected="selected">By Client</option>
    	 <?php
        $args=array(
    
          'post_type' => 'our_work',
          'post_status' => 'publish',
    	  'order' => 'ASC',
          'posts_per_page' => -1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
    	$k=0;
    	if( $my_query->have_posts() ) {
    	while ($my_query->have_posts()) : $my_query->the_post();
    
         $termArray = array (trim(get_the_term_list( $post->ID, 'client_name')));
    
         // $text = trim(get_the_term_list( $post->ID, 'client_name'));
    	  for ($i = 0; $i <= $termArray.count; $i++ ) {
    			for ($j = 0; $j <= $tempArray.count; $j++) {
    				if ($tempArray[$i] == $tempArray[$j]) {
    
    					unset($tempArray[$k]);
    					$termArray = array_values($termArray);
    				}
    			} // end of for
    	 $k++; ?>
    	 <option value="<?php bloginfo('url'); echo "/client_name/"; echo $termArray[$k]; ?>"><?php echo $termArray[$k]; ?></option>
    	<?php } ?>
    
    	<?php endwhile; } wp_reset_query(); ?>
        	</select>
    		<input type="submit" id="clientsubmit" value="Search" />
    		</form>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude duplicated custom taxonomy within custom post type.’ is closed to new replies.