Trying to get custom post of a custom taxonomy

I can’t get the first bit to work, I can’t get the taxonomy to return the post. So the following is the first bit which queries posts in a single taxonomy term: $posts_array = get_posts( array( ‘showposts’ => -1, ‘post_type’ => ‘treatment’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘treatment_type’, ‘field’ => ‘term_id’, ‘terms’ => $term->slug, … Read more

Started getting warning message following host’s PHP upgrade

The issue is this line: if(function_exists(register_setting)) register_setting is not in quotes. Values without quotes are how you refer to constants in PHP, but there’s no constant with that name, because it’s supposed to be ‘register_setting’, with quotes. PHP recognises this mistake, and is interpreting this as if you had included the quotes, but it’s warning … Read more

Warning message (re. php) on the blog page

<a href=”https://wordpress.stackexchange.com/questions/364537/<?php//echo esc_url( home_url(“https://wordpress.stackexchange.com/” ) ); ?>”><?php// bloginfo( ‘description’ ); ?></a> The <?php// is the problem. PHP blocks are started with <?php but the code uses <?php//. Instead, change it to <?php //, or better yet, since // is meant to comment an entire line out, use /* */ style commenting instead

Notify users only on post publish

You could use the transition_post_status hook instead, as it already knows what the current and previous status of the post are. <?php add_action(‘transition_post_status’, ‘wpse_366380_email_on_publish’, 10, 3); function wpse_366380_email_on_publish( $new_status, $old_status, $post ) { // Only if this post was just published, and previously it was either // “auto-draft” (brand new) or “pending” (not yet published) … Read more

Find hours between post_date and post_date_gmt

If all you need to do is check the difference, rather than display or modify anything, then you don’t need to do anything complicated with date_diff(). All you need to do is compare the number of seconds returned by get_post_time() for each date. get_post_time() returns the Unix timestamp for the date, which is simply the … Read more

Is it bad to add html to a widget by closing and reopening the php tags?

“Practice” is a matter of personal preference. The opening and closing PHP tags (<?php and ?>) are there as a matter of convenience. Basically, try to write your code in context. In example, // PHP code here ?><a href=”https://wordpress.stackexchange.com/questions/368897/<?php the_permalink() ?>”><?php the_title() ?></a><?php // PHP code here looks (to me) like HTML code plopped right … Read more