How to get comment_ID by post_ID in wordpress

Use get_comments( $args ) to get all the comments for a post. $args= array( ‘author_email’ => ”, ‘ID’ => ”, ‘karma’ => ”, ‘number’ => ”, ‘offset’ => ”, ‘orderby’ => ”, ‘order’ => ‘DESC’, ‘parent’ => ”, ‘post_id’ => 0, ‘post_author’ => ”, ‘post_name’ => ”, ‘post_parent’ => ”, ‘post_status’ => ”, ‘post_type’ => … Read more

Looping through 3 recent posts but separating them into separate divs

This isn’t really a WordPress question, but all you need to do is setup a counter for the class integer that you want, as follows: <?php // Create a variable to hold our custom Loop results $excludes = array(‘4135’); $frontpageposts = get_posts( array( ‘numberposts’ => 3, // only the 3 latest posts ‘post__not_in’ => $excludes … Read more

Displaying Event within two given time frames

Querying on the meta data table is slow, and as since it’s also used for general data, you need to be careful about your date format if you’re storing dates there. For instance, with dmY format: 01112014 ( 1st November 2014 ) 11012014 ( 11th January 2014 ) 12052014 ( 12th May 2014 ) is … Read more

Taxonomy term count

You can use WP_Query Methods and Properties to accomplish this. $wp_query->found_posts will return the amount of posts within the term while $wp_query->queried_object->name will return the name of the term currently displayed. You can now just paste all these together to display 18 free resources $taxcount = $wp_query->found_posts; $taxname = $wp_query->queried_object->name; printf(__( ‘%s %s resources’ ), … Read more

Custom navigation menu with awsAccordion

After reading PHP and wordpress codex i achieved what i wanted, by making a walker class. Here is the code class Hambos_Walker_Nav_Menu extends Walker_Nav_Menu { function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); if ($depth == 0): $output .= “\n$indent <div>\n”; else: $output .= “\n$indent <ul>\n”; endif; } … Read more

posts_nav_link pulling in multiple post types

query_posts should be avoided at all costs. This is not just my emphasis, but the codex’s as well Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query … Read more

PHP if have image display image, if else text

I posted this question on stackoverflow, and got this answer from @cmorrissey. Credit goes to him for this code. <?php if($novus_logo_upload = get_option(‘novus_logo_upload’)){ ?> <!– Logo Image –> <a href=”https://wordpress.stackexchange.com/questions/149443/<?php bloginfo(“url’); ?>/home” title=”<? echo esc_attr( get_bloginfo( ‘name’, ‘display’ ) ); ?>” rel=”home”> <? echo ‘<img class=\”logo”\ src=”‘.$novus_logo_upload.'” width=\”100%”\ />’; ?> </a> <?php } else if($novus_logo_text … Read more

Dynamic CSS through PHP issue

Wow I am an idiot. Ok, here is my error. .contain-to-grid .top-bar { background-color: <?php echo $novus_nav_color; ?>; } I needed to just echo the variable and it was trying to call a string.

Dynamically Generate Functions and Hooks

Since Milo is a genius, I got this done much simpler by just looping through the array inside of the function, instead of trying to generate a new function dynamically for each item. The array contains ‘slug’ and ‘title’ attributes, and here’s the function: function cx_product_field() { global $fieldset; foreach ( $fieldset as $field ){ … Read more