Display a single category in blog section

In WordPress, we have what is called as “main query” which points to the global $wp_query object (which is an instance of the WP_Query class), and this main query is run on page load after WordPress parses query arguments from the current URL (or the relevant query for the matching rewrite rule for that URL). … Read more

How to create custom popup in shop page on every loop products?

Use below code. Tested and Worked perfectly. functions.php add_action( ‘woocommerce_after_shop_loop_item’, ‘product_visibility_button’, 5 ); function product_visibility_button() { if ( is_user_logged_in() ) { $user = wp_get_current_user(); if ( in_array( ‘administrator’, (array) $user->roles ) ) { ?> <button type=”button” class=”button” id=”but” style=”margin:10px” >Open Popup</button> <div style=”display: none;” class=”pop-outer”> <div class=”pop-inner”> <button class=”close”>X</button> <h2>This is a custom pop-up example</h2> … Read more

Multisite foreach loop returning only one result

Each pass through the foreach() loop, you’re wiping out the values that are already in your $urls array. Try something like this: function rel_alternate_network(){ global $post; $slugX = is_main_site() ? $post->post_name : rtrim($post->post_name, ‘-in-‘.strtolower(do_shortcode(‘[country]’))); $urls = array(); foreach(get_sites() as $site){ if( $site->blog_id == get_current_blog_id()) {continue;} switch_to_blog($site->blog_id); $slugY = get_post_by_slug($slugX); $new_url[‘site’] = $site->path; $new_url[‘slug’] = $slugY->post_name; … Read more

First archive page with a few posts

This is my archive template — page-archive.php, which I am using as a template to display all my posts/recipes So if you’re using a Page (post of the page type) with a custom/specific Page Template, then you should create a secondary query and loop for retrieving and displaying your recipes/posts. But even with a default … Read more

Custom loop ordering not working

“sort_order” => “ASC”, “sort_column” => “post_name” These are not sorting parameters. Use order and orderby instead as specified in the official documentation: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

For each loop on every word in post

Are you sure you want to link every instance of each ingredient? As a user, I wouldn’t mind if the ingredient list above the recipe had all its ingredients linked, but if the following instructions continued linking every ingredient I’d find that to be a lot of links I could accidentally tap on and lose … Read more

Category links including all posts

The <?php query_posts(); ?> in your code is causing the global query to be reset to show all posts instead of the one set by your rewrite rules. You should remove that line.

Loop Offset for tag based “Related Posts”

doing 3 separate queries is unnecessary and inefficient, do one query for all 12 posts and output your container markup every fourth post. $args = array( ‘tag__in’ => $tag_ids, ‘post__not_in’ => array($post->ID), ‘posts_per_page’=> 12 ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ): ?> <div class=”container”> <?php while ( $my_query->have_posts() ) : $my_query->the_post(); the_title(); … Read more