Forum Replies Created

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter danhodkinson

    (@danhodkinson)

    Ok so it’s almost as if i need code that goes through the loop and if it finds a taxonomy it checks if there are any other posts in that taxonomy, and maybe adds that to an array to say it’s been ‘checked’ so that when it gets to a product further down the line in the same taxonomy as before it knows it’s already been dealt with? i.e (in very rough code)

    $array = []
    if (post_has_term and is not in $array ) {
      output the_term_name
      foreach (post in post_has_term) {
         output the_title()
      }
      the_term_name push in to array
    else {
      output the_title()
    }

    i could possibly make that work (although there must be a simpler way?) but the one thing that still doesn’t help me do is alphabetise everything. If the product was aardvark in the category zoo animals then the list would go

    Zoo Animals
    Giraffe
    Lion

    because it’s finding aardvark first but outputting it’s taxonomy name?

    If you follow that logic?

    Thread Starter danhodkinson

    (@danhodkinson)

    Also, once i’m in the post loop, it’s going to throw the A-Z order out, as I’ll be then telling it to show the taxonomy name of the post, which would be different from the post name.

    Thread Starter danhodkinson

    (@danhodkinson)

    This is all done in my own theme so there shouldn’t be any issues with child themes.

    I’ll investigate the wp_get_post_terms(), but my immediate reaction is that will create lots of the same titles for posts.

    E.g. if i have the following products:

    Adidas
    Nike
    Reebok
    Puma
    Umbro

    Nike and puma are in the taxonomy ‘premium’

    So the loop as I want it would output:

    Adidas
    Reebok
    Premium
      - Nike
      - Umbro
    Puma

    I can’t help but feel it will output:

    Adidas
    Reebok
    Premium
      - Nike
    Premium
      - Umbro
    Puma

    As i’m not looping through the term to get the posts? if that makes sense?
    Either way i’ll investigate further!

    Thread Starter danhodkinson

    (@danhodkinson)

    Hi moondrop,

    Thanks for this. I ‘semi’ got it working but I couldn’t get ‘downloads’ to share/use the information from ‘yourproduct’. I’ll keep trying, but just wondering if there’s something else I should be doing to get that part to work?

    Thanks
    Dan

    Thread Starter danhodkinson

    (@danhodkinson)

    So i got everything working, but the way i’ve got it working i’m unsure how to merge the posts together so that I can have this listed A-Z?

    Basically what i’m doing is running a query loop to get all of the posts that don’t have my custom taxonomy applied to it.
    Then I do a secondary loop to get all of the posts that ARE in my taxonomy, with those posts i check which taxonomy they are a part of and add them as a child. This spits out two lists wonderfully, but it lists the posts and then the cats containing the posts. i.e.

    – Product A
    – Product C
    – Product B (actually a cat)
    — Product in Cat 1

    Anybody have any clue if I can add a step somewhere to mix them all together to sort them correctly

    <?php $terms = get_terms( 'need_cat' );
    // convert array of term objects to array of term IDs
    $term_ids = wp_list_pluck( $terms, 'term_id' ); ?>
    
    <?php $query1 = new WP_Query( array( 'post_type' => 'product_info', 'order' => 'ASC', 'orderby' => 'title',
    	'tax_query'	=> array(
            array(
                'taxonomy'  => 'need_cat',
                'terms' => $term_ids,
                'field' => 'term_id',
                'operator'  => 'NOT IN'
            )
        ),
    ));?>
    
    <?php
    
    $query = new WP_Query( array( 'post_type' => 'product_info',
    	'tax_query'	=> array(
            array(
                'taxonomy'  => 'need_cat',
                'terms' => $term_ids,
                'field' => 'term_id',
                'operator'  => 'IN'
            )
        ),
       ));
    $q = array();
    
    while ( $query->have_posts() ) {
        $query->the_post();
        $a = '<a href="'. get_permalink() .'">' . get_the_title() .'</a>';
        $categories = get_terms('need_cat');
        foreach ( $categories as $key=>$category ) {
            $b = '<li class="productCat toggle">' . $category->name;
        }
        $q[$b][] = $a; // Create an array with the category names and post titles
    }
    
    /* Restore original Post Data */
    wp_reset_postdata();
    // print_r($q);
    foreach ($q as $key=>$values) {
        echo $key;
        echo '<ul>';
            foreach ($values as $value){
                echo '<li>' . $value . '</li>';
            }
        echo '</ul></li>';
    }
    ?>
    
    <?php if (have_posts()): while ( $query1->have_posts() ) : $query1->the_post();?>
    	<li>
    		<a href="<?php the_permalink();?>"><?php the_title();?></a>
    	</li>
    <?php endwhile; endif; ?>
    Thread Starter danhodkinson

    (@danhodkinson)

    Yep.

    If i could get it to spit out the tree consistently on all 3 levels (parent, child, grandchild) then I would just do it with CSS.

    The closest I have come to that is only showing the children and grandchildren, I can’t get it to include the parent in that.

    <?php
    							if(!$post->post_parent){
    								$children = wp_list_pages("depth=0&title_li=&child_of=".$post->ID."&echo=0");
    								echo "here";
    							}else{
    								$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    
    								if($post->ancestors)
    								{
    									$ancestors = end($post->ancestors);
    									$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
    									// you will always get the whole subpages list
    								}
    							}
    
    							if ($children) { ?>
    								<ul class="blank">
    									<?php echo $children; ?>
    								</ul>
    						<?php } ?>
    Thread Starter danhodkinson

    (@danhodkinson)

    This is a custom theme.

    Thread Starter danhodkinson

    (@danhodkinson)

    I’ve got the custom post type archive working..
    but it bases it’s archive on the publish date of the article, not the specified program date, which means it won’t work properly for future programs that i publish today.

    Thread Starter danhodkinson

    (@danhodkinson)

    Yeah i’ve never had any luck with that plugin on other custom post types and it’s the same here.

    It’s very frustrating as it should be a simple thing to achieve!

    Thread Starter danhodkinson

    (@danhodkinson)

    I have done, but how do i access them/enter the code to show them?

    Thanks
    Dan

    Thread Starter danhodkinson

    (@danhodkinson)

    Thanks for that!

    i’ve found that
    <?php if ( $EM_Event->output('#_EVENTIMAGE') ) = ' '): ?>
    also works, so i’ll play about with both and see which i get along with

    Thread Starter danhodkinson

    (@danhodkinson)

    in my template i am using:
    `<?php echo $EM_Event->output(‘#_EVENTIMAGE’);?>’
    to show an image.
    Using echo do shortcode in the template doesn’t seem to work.

    Dan

    Thread Starter danhodkinson

    (@danhodkinson)

    i’ve managed to sort it.
    if anybody is ever interested:
    I just had to find out the ID of the page I was grabbing
    $id = $page_data->ID;

    and then pass that in to the $meta call:
    $meta = get_post_meta( $id, 'the_text', true );

    thanks
    dan

    Thread Starter danhodkinson

    (@danhodkinson)

    I’ve just come back to this but still can’t figure it out?
    Anybody have any suggestions?

    Thread Starter danhodkinson

    (@danhodkinson)

    still haven’t figured this one out.

Viewing 15 replies - 1 through 15 (of 21 total)