WordPress custom query by archive title

I have just made this on a rush but would you please try this : <?php if( is_tag() ){ $tag = single_tag_title(”, false); }else{ $tag=”; } if( is_category() ){ $cat = single_cat_title(”, false); }else{ $cat=””; } $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘tag’ => $tag, ‘posts_per_page’ => $ppp, ‘category_name’ => $cat, ‘offset’ … Read more

Getting the last X posts, but in ascending order of time

Have you tried the last parameter with ASC like ‘order => ‘ASC’ ? I think it will solve your problem. So your full code will be like- // get posts $posts = get_posts(array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 2, ‘meta_key’ => ‘from_datetime’, ‘orderby’ => ‘meta_value’, // Here is the main trick happening. ‘order’ => ‘ASC’ … Read more

how to show more than 1 post into three columns query

I haven’t tested it but see if that works Assign values to variables before begining of while loop $c = 1; $counter = 5; Change your all $couter if conditions if($counter == 1) if($counter == 2) if($counter == 3) into this respectively if($counter % $c==1 || $counter % $c==2) if($counter % $c==3) if($counter % $c==4 … Read more

Related Posts with removing some categories

You can use the category__not_in parameter to exlude categories. get_posts uses the WP_QUERY parameters Your code will be : $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID), ‘category__not_in’ => array(1,2,3,4)’ ) );

I cannot get tax_query in get_posts() to work with custom taxonomy

Does your custom post type have the setting publicly_queryable=true? Check the post type in the resulting query to see if it matches your post type. I’m guessing that your post type ‘distribution_centre’ is not being queried for one reason or another. add_filter( ‘posts_request’, ‘dump_request’ );//show the query function dump_request( $query ) { echo “<pre>”; var_dump( … Read more

Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?

After several hours of debugging I have found what caused the problem. Custom taxonomy ‘cadassist_category’ is used for 2 custom post types: product_document and cadassist_file. The posts for taxanomy with ID 653 were of cadassis_file type. And I tried to get posts of product_document type. That is why I got empty array. So if you … Read more

Get current user, change users post status to published

The database holds several rows for each attribute of a post. All except on row should have status inherit. So I just hope the post_id is correct. Anyway, yes you are correct to assume that it is similar: $query = array( ‘ID’ => $post_id, ‘post_status’ => ‘publish’, ); wp_update_post( $query, true ); Oh and add_action(‘publish_post’… … Read more

Adding additional taxonomies to wordpress taxonomy page

// 12 – difficulty // destination // get Id current taxonomy $this_term = get_queried_object(); $taxquery = array( ‘posts_per_page’ => 1, ‘post_type’ => ‘packages’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘difficulty’, ‘field’ => ‘id’, ‘terms’ => array( 12 ), ), array( ‘taxonomy’ => ‘destination’, ‘field’ => ‘id’, ‘terms’ => array( $this_term->term_id) // Id … Read more