“is_new_day()” alternative for years?

You could create a helper function that returns a year number only once per year: function get_unique_year( $post_id = 0 ) { static $last = 0; $post_id || $post_id = get_the_ID(); $year = get_the_time( ‘Y’, $post_id ); if ( $year === $last ) return; $last = $year; return $last; } Then fetch your posts and … Read more

How to fix Warning: call_user_func_array()?

Not sure this will help but after dealing with the exact same error message for the last 2 days I finally figured out what was happening. It was simply a matter of attempting to call the function before the system knew it existed. In my case, I had written the function in a separate–not-publicly-accessible–directory and … Read more

Woocommerce Attributes pulling in wrong data

You are confusing get_terms() with get_the_terms() get_terms() returns an array all the terms in a taxonomy. get_the_terms() returns an array of all the terms for a particular post. global $post; $terms = get_the_terms( $post->ID, ‘pa_size’); foreach ( $terms as $term ) { echo “<li>” .$term->name. “</li>”; } You might also like get_the_term_list() which would be … Read more

Empty Date Returned on my function

Replace the_date() with the_time() and it should work fine. the_date() only displays the date for posts that are on different days. If two posts are published on the same day, only the first one’s date will be displayed.

example of build_query function?

build_query() converts an array into a string to be used in an URL. You can pass an array or an object: $test1 = array ( ‘foo’ => ‘bar’, ‘hello’ => ‘world’ ); $query1 = build_query( $test1 ); print “<pre>$query1</pre>”; // foo=bar&hello=world $test2 = array ( ‘foo’ => ‘bar’, ‘hello’ => ‘world’, ‘one’ => array( 1, … Read more

wp_trash_post function to only apply to posts, not pages!

You could just add something like: // Remove 1 point if their post get removed function deletePointFromUser($post_id) { $post = get_post($post_id); if( $post->post_type != ‘post’ ) return;//added code $authorid = $post->post_author; $currentQPointNumber = get_user_meta($authorid, ‘points’, true); // Delete 1 to the current Point Score update_user_meta($authorid, ‘points’, $currentQPointNumber-1); } add_action(‘wp_trash_post’, ‘deletePointFromUser’); Then your point subtraction will … Read more