Display all categories as plain text

This is a general solution for all taxonomies. To be used inside the loop (else replace get_the_ID() with post ID ): $taxonomy = ‘category’; $terms = get_the_terms( get_the_ID(), $taxonomy ); if( $terms ){ $term_slugs = array_map(‘esc_attr’,wp_list_pluck( $terms, ‘slug’)); $class = implode(‘ ‘, $term_slugs); }else{ $class=”no-term”; }

How do i create a list-posts-page?

Assuming you’re only trying to display your blog posts index on a page other than the front page (i.e. because you’ve assigned a static page as your site front page), you shouldn’t need to do anything special. Refer to the Codex for step-by-step instructions for creating a static front page and separate page for your … Read more

Pagination for two loops

You have to pass pagination parameters to your queries as well. As it is, you are just pulling 5 posts. By default that is going to be the most recent five. Then another query pulls the next five. The fact that you are trying to paginate two loops makes this trickier than normal. However… At … Read more

Using has_tag() outside loop

The has_tag() conditional does not have to be used inside the Loop; it can be passed a $post object as a second parameter: has_tag( $tag, $post ); Since has_tag() defaults to the current post, you simply need to pass it the object for the next adjacent post. Fortunately, WordPress provides a function to retrieve adjacent … Read more

How to use this $tax_selection variable in this custom loop?

I suppose you need to make it global. It might look like: add_action( ‘pre_get_posts’, ‘do_user_post_selection’ ); function do_user_post_selection( $query ) { if( !is_home() || !is_user_logged_in() ) return; if( isset( $query->query_vars[‘post_type’] ) && ( ‘nav_menu_item’ == $query->query_vars[‘post_type’] ) ) return; if( 1 < did_action(‘wp’) ) return; global $current_user, $tax_selection; $tax_selection = get_user_option( ‘taxonomy_selection’, $current_user->ID ); if( … Read more

Does search.php autofilter The Loop?

The loop doesn not display the latest posts, it just shows the posts the main query has found. On your search page the main query returns search results, and you can change its order (we have plenty of examples for that on our site). WordPress looks for the parameter s or /search/ in the request … Read more

How can I access a post’s feature image outside the loop?

On a single post page the $post variable should work for you. It is set well before the page header prints. You will need get_post_thumbnail_id and wp_get_attachment_image_src if (is_single()) { $thumbid = get_post_thumbnail_id($post->ID); $imgsrc = wp_get_attachment_image_src($thumbid); $src = $imgsrc[0]; // wp_die(var_dump($src)); // debugging/confirmation } I don’t know how your theme is written or how that … Read more

how to run loop in function.php that sends email based on specific conditions?

The post’s data is passed as an argument to the function hooked to transition_post_status, so you don’t need to query for anything (also, your query is a bit strange, using both WP_Query and query_posts, but that’s a separate matter). Here’s a trimmed version of your function showing the important changes: function a_new_post( $new_status, $old_status, $post … Read more