get listed category’s id?
How about get_query_var(‘cat’). I think that should get the ID of the current category.
How about get_query_var(‘cat’). I think that should get the ID of the current category.
take a look at this plugin : Multi-Site Site List Shortcode or if you prefer a snippet then: $blog_list = get_blog_list( 0, ‘all’ ); if (count($blog_list) > 1){ echo ‘<ul>’; foreach ($blog_list AS $blog) { echo ‘<li>Blog ‘.$blog[‘blog_id’].’: ‘.$blog[‘domain’].$blog[‘path’].'</li>’; } echo ‘</ul>’ }
If you use the follow code: <?php $cats = get_categories(‘child_of=6’); foreach ($cats as $cat) : $this_category = get_category($cat); $args = array( ‘category__in’ => array($cat->term_id) ); $my_query = new WP_Query($args); if ($my_query->have_posts()) : ?> <li><a href=”https://wordpress.stackexchange.com/questions/41725/<?php echo get_category_link($cat); ?>”><?php echo $cat->name; ?></a> <?php if ($this_category->category_parent != 0) { ?> <ul class=”children”> <?php while ($my_query->have_posts()) : $my_query->the_post(); … Read more
I can only see achieving this by first building an array, then looping over it – I can’t find anything in APC’s docs about checking if it’s the last iteration of the_repeater_field: $images = array(); while ( the_repeater_field( ‘homepage_service’ ) ) $images[] = get_sub_field( ‘service_image’ ); if ( $images ) { $image_last = array_pop( $images … Read more
add a simple counter and conditional check: $pages = get_pages(‘child_of=10’); $counter = 1; if ($pages) { echo ‘<ul class=”projectthumbs”>’; foreach ($pages as $page) { if ($counter == 3){ $class=” class=”YOUR_CLASS””; $counter = 1 }else{ $class=””; $counter = $counter +1; } echo ‘<li’.$class.’><a href=”‘.get_permalink($page->ID).'”>’; echo get_the_post_thumbnail($page->ID); echo ‘<span class=”projectthumbtitle”>’; echo get_the_title($page->ID); echo ‘</span>’; echo ‘</a></li>’; } … Read more
You could do a custom SQL query: global $wpdb; $query = “SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = ‘director’ ORDER BY meta_value;”; $directors = $wpdb->get_results( $query ); foreach( $directors as $director ) : echo $director->meta_value; endforeach; one thing to note here though is that since you’re not querying the associated posts, you could get … Read more
You have to call the_post() within your loop, otherwise you’ll output the first post in an infinite loop, as have_posts() will always be true. $queryScience->the_post(); Also, you don’t need wp_reset_query() with WP_Query, wp_reset_postdata() is enough.
I’ve modified above function somewhat function get_event_list( $latest = true, $order=”ASC”, $return = false, $year ) { // Pass year i.e $year $enddate = strtotime($year.”-12-31″); // year’s last date $startdate = strtotime( ($year-1).”-12-31″); year’s first date $yesterday = array($startdate, $enddate ); // Fetch posts between these dates $compare=”BETWEEN”;// Between above two dates $current_year=””; $args = … Read more
Use get_users function it allows you to query user by role. For contributors, $contributors = get_users(‘role=contributors’); foreach($contributors as $contributors){ // do something with contributors } For Admins, $admins = get_users(‘role=admin’); foreach($admins as $admins){ // do something with admins } replace role=* with your desired roles.
Instead of counting inside your foreach loop, why not count the result from get_the_terms. Something like this $q = count($producers); From that, you can then use a conditional like if( 1 == $q ) { // do something when only one term exists }else{ // do something for mutliple terms }