danhodkinson
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Is this kind of loop achievable?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?
Forum: Developing with WordPress
In reply to: Is this kind of loop achievable?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.
Forum: Developing with WordPress
In reply to: Is this kind of loop achievable?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!Forum: Fixing WordPress
In reply to: Child of single-{cpt} template?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
DanForum: Fixing WordPress
In reply to: Odd loop needed: Exclude post if post is in ANY categorySo 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 1Anybody 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; ?>
Forum: Fixing WordPress
In reply to: Navigation (Parent, Child, Grandchild)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 } ?>
Forum: Fixing WordPress
In reply to: Navigation (Parent, Child, Grandchild)This is a custom theme.
Forum: Plugins
In reply to: [Events Manager - Calendar, Bookings, Tickets, and more!] Event ArchiveI’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.Forum: Plugins
In reply to: [Events Manager - Calendar, Bookings, Tickets, and more!] Event ArchiveYeah 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!
Forum: Plugins
In reply to: [Events Manager - Calendar, Bookings, Tickets, and more!] Event ArchiveI have done, but how do i access them/enter the code to show them?
Thanks
DanThanks 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 within 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
Forum: Fixing WordPress
In reply to: get_pages bring in custom meta valuesi’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
danForum: Fixing WordPress
In reply to: Custom Category ConfusionI’ve just come back to this but still can’t figure it out?
Anybody have any suggestions?Forum: Fixing WordPress
In reply to: Custom Category Confusionstill haven’t figured this one out.