Check if term object is in array

WordPress has the wp_list_pluck function, which can be helpful here. We can make an array of just term IDs from the array of objects like: $term_ids = wp_list_pluck( $subcat_terms, ‘term_id’ ); Then we can check in_array: $this_id = 42; if( in_array( $this_id, $term_ids ) ){ // do something }

Use is_product_category() properly

is_product_category() is to be used on woocommerce category archive pages only so first make sure that you are on category archive. instead of category number use category slug name is_product_category(‘category-slug’) no need to run OR(||) condition just use is_product_category(‘category-slug1′,’category-slug2’) to get same output

Styling images coming from another blog

Calling image_resize() would be difficult, since it would search for the image in your main blog’s upload directory. If it is a fixed image size I would just add it to the configuration of your photoblog, so it is created there when you upload new images (you can then rebuild your old image thumbnails). In … Read more

page template for attachement page?

WordPress supports several types of attachment templates. The function get_attachment_template in wp-includes/theme.php provides this support; it is called in wp-includes/template-redirect.php. If your theme includes attachment.php all of your attachments will be rendered with that template. If your theme also includes image.php then all of your images will use that template as long as they have … Read more

WordPress WP_Query() Not working properly

a possible conflict with the name $posts which is used by wp core; try, for instance: $categories = get_categories(); foreach($categories as $category) { printf(‘<h2>%s</h2><ul>’, $category->cat_name); $cat_posts = new WP_Query(‘cat=”.$category->cat_ID); while($cat_posts->have_posts()) { $cat_posts->the_post(); echo “<li>’, the_title(), ‘</li>’; } print ‘</ul>’; }

Convert a date to ISO8601 date format

Use the_time or get_the_time, which accept the same format parameters as php’s date. // assign to a variable $iso8601_date = get_the_time(‘c’); // or output directly the_time(‘c’); EDIT- converting formats with php: $date = “September 11, 2011 9:00 am”; $time = strtotime( $date ); echo date( ‘c’, $time );

Warning when using

The WordPress method to include php files is to use this function: <?php get_template_part(‘myfile’); ?> which will include the file myfile.php that is in the same template directory. See http://codex.wordpress.org/Function_Reference/get_template_part for other parameters.

Generating add_settings_section() calls dynamically

Try this instead: function settings_sections() { // array containing settings identifiers $array = ( ‘SOMETHING’, ‘SOMETHING2’, ‘SOMETHING3’, ‘SOMETHING4’ ); // loop through settings identifiers and generate settings sections foreach( $array as $v) { add_settings_section( $v . ‘_settings’, $v . ‘ Settings’, ‘generate’, $v . ‘_page’ ); } } echo outputs a string, you should just … Read more

Different background-image by category

You can do this using WordPress’s handy body_class() function. Depending on whether and how it is used in your theme, it may already be giving you what you need. Here’s how to find out: Check the source of your page to see if the <body> tag in your category archive pages has any classes containing … Read more