Articles of loop

Looping through posts per category gives same posts for each category

For a specific section on my website I loop through some categories and get the three latest posts in that categorie and list them. Like so: <?php $categories = get_categories(array(‘exclude’ => ‘1, 4, 9, 10, 2899’)); ?> <?php foreach ($categories as $category) : ?> <div class=”subject”> <h3><?php echo $category->cat_name; ?></h3> <ul> <?php $args = array( […]

How to call custom single post?

newbie here playing with php stuff, wanna learn. So the problem is. I have created custom posts and data from those is shown in a widget. Now i want to create custom single posts for those custom posts (dont get confused,yet). I have single.php which shows my post and with inside it i say if […]

Better way to display posts from specific categories, in a grid layout

I’m using the following code to display posts from a specific category, in a grid layout, on my home page. It works exactly how I want it to, but I keep reading that I shouldn’t ever use query_posts. How can I achieve the same results, without using query_posts? Also, I will eventually need to display […]

Get Pagination (WP-PageNavi) not to work

I have several problems to get the pagination work. I have a custom page template, in there i need to display all blog posts. I build up the following “query” and build up my html structure: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, […]

get_template_part for each level of taxonomy term

before we start, thank’s for your time. Structure: cpt = corsi tax = argomenti tax_term = parent tax_term_child = child tax_term_child_granchild = grandchild Current code (on taxonomy-argomenti.php): $queried_object = get_queried_object(); $cpt = get_post_type( get_the_ID() ); $taxonomy = $queried_object->taxonomy; $term_id = $queried_object->term_id; $current_term = get_term_by(‘id’, get_query_var(‘term’), $taxonomy); if((int)$current_term->parent) get_template_part(‘argomenti’, ‘child’); else get_template_part(‘argomenti’, ‘parent’); I would choose […]

How to pass many ids in post__in?

I need to pass many ids to the parameter post__in in args. This not work !!! Help me please. foreach ($rows as $obj) { $todos .= $obj->ID . “,”; } $ids = trim(trim($todos), “,”); # echo $ids output ——-> 613,647 $args = array ( ‘post_type’ => ‘professores’, ‘post__in’ => array($ids) <—– Don’t work ); How […]

How to Display a Single Post Excerpt

Is it possible to show the excerpt for a known and single post (on the Home Page) while in the loop? I tried each of these and none of them work: <?php echo the_excerpt(’10’); ?> <?php echo the_excerpt(10); ?> <?php $theExcerpt = get_the_excerpt(’10’); echo $theExcerpt; ?> <?php $theExcerpt = get_the_excerpt(10); echo $theExcerpt; ?>

Loop through pages with specific template

I would like to know how I can loop through pages with a specific template name. I have several pages where the admin can select a template name of SALE. I want to display all content with this template name via the loop. Any ideas are much appreciated!

post loop causes wp_users and wp_usermeta DB queries for each users

Continuing my previous question: My post loop produces 2 queries per post: SELECT * FROM wp_users WHERE ID = ’53’ require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/BT/search.php’), the_post, WP_Query->the_post, WP_Query->setup_postdata, get_userdata, get_user_by, WP_User::get_data_by #20 (0.1ms) SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE user_id IN (53) ORDER BY umeta_id ASC require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/BT/search.php’), the_post, WP_Query->the_post, WP_Query->setup_postdata, get_userdata, get_user_by, WP_User->init, WP_User->for_blog, […]

Exclude category by slug for for each loop

I am trying to exclude some categories from a for-loop. <?php $categories = get_categories(array(‘exclude’ => ‘apps, windows’)); ?> <?php foreach ($categories as $category) : ?> // the_loop <?php endforeach; ?> Even though no error is thrown, it doesn’t work: all categories are used in the loop. How can I exclude some categories by slug? I […]