Check if tag contains posts

You can use: <?php if (get_tag(’17’)->count > 0) { ?> <?php } ?> get_tag is basically a get_term with taxonomy post_tag and get_term returns WP_Term object on success, WP_Error on error. WP_Term has property $count which has object count for the term in process.

Missing a text-domain esc_attr_e

Don’t know about the error but the strings that are being translated need to be constant strings, not dynamic values. if $l10n[‘no-image-selected’] is already translated then use esc_attr and not esc_attr_e

PHP $_REQUEST array empty

Missing GET request variables are sometimes a symptom of improper rewrite rules in the web-server’s configuration files. In the case of Apache, rewrites are most often implemented using the mod_rewrite module’s directives in the WordPress installation’s directory-level .htaccess configuration file – however, a faulty rewrite rule could also be present in higher-level configuration files (directory, … Read more

add category to posts with tag wordpress

This is just an example to get all posts in the category transportation with the tag car : $args = array( ‘post_type’=>’post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘transportation’ ), ), array( ‘taxonomy’ => ‘tag’, ‘field’ => ‘slug’, ‘terms’ => array( ‘car’ ), ‘operator’ => … Read more

Amend theme php to include certain category in header

You can use the action pre_get_posts. It gets fired after the query object is created but before the query is run. This is an example from the official documentary for displaying only one category: In your functions.php add the following: function my_home_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘123’ … Read more

How to override a plugins script

In principal, unless there are documented APIs and/or filters to the plugin, you should not do anything that is more then using core hooks if you want to be able to upgrade it in the future. If no appropriate thing is available, you should contact the author and ask for it, or decide that you … Read more

Using bloginfo and divs inside a php file

I assume you’re wanting an image tag in there too: if ( $colors && in_array( ‘green’, $colors ) ) { echo ‘<div class=”asdsf”><img src=”‘; echo bloginfo(‘template_directory’) . ‘/path/within/theme/to/img.png’; echo ‘”></div>’; } But it’s better to use the newer get_stylesheet_directory_uri() which will work whether or not you are using a child theme. if ( $colors && … Read more

Show site content based on user role

You have errors in the code First, you are using current_user_can() function the wrong way. It has two parameters — $capability and $object_id. You don’t need the latter one, so, in your case: current_user_can(‘subscriber’) In my opinion, it’s better to use capability instead of user role in this function. For example, subscribers can’t edit posts, … Read more