Articles of wp query

Query by Category and Custom Field – Shortcode

I have been working on a shortcode to Query by a Specific Category and display all posts in the category if the specified custom field is populated. What I have created to this point was started with code I found and I made changes to fit my needs. I have updated the code using the […]

WP Query issue for multiple values

I have a custom field with the key colour and the value can either be red or blue for individual posts. I know the code to return posts that are either red or blue i.e. ?colour=red, but I don’t know the code to return posts that are either red or blue i.e. ?colour=red&colour=blue. I have […]

How to create page that lists tags by initial letter?

I want to create a page that lists tags that begin with a specific letter. So for example I want a page that lists all tags that begin with the letter ‘A’. This is the code I got so far <?php $args = array(‘name__like’ => “a”, ‘order’ => ‘ASC’); $terms = get_terms(‘post_tag’, $args); if ( […]

Alter query on frontend for custom post types

I have two custom post types – movies and songs. They both share same categories. I’d like to make possible filtering content in category.php pages by users visiting my website. For example they click “show only movies” and it would show only post_type=movies in query. Is it possible? My query code: <?php // WP_Query arguments […]

Filter Custom post type by another Custom post type

Assume, i have two custom post types – Project and Technology. Every project has a relation to Technology (using ACF). The question is – How to filter it by Technology. I tried this approach: ‘post_type’ => ‘project’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘technology’, ‘value’ => $_GET[‘technology’], ‘compare’ => ‘LIKE’, ), array( […]

WP_Query doesn't return some child pages even though the database shows them

I have several pages all under one parent like this ParentPage (ID 24) ChildPage A ChildPage B ChildPage C ChildPage D ChildPage E ChildPage F I am using WP_Query to return all the child pages but only some are coming back. In the DB all the child pages have the same parent ID of 24. […]

WP_Query Not Working with Variable

If I use this code(code not complete, this is the problem section), the posts appear properly. NOTE the “new WP_Query(‘cat=2,3,5,6,7,8,9’);”: $catslugs = array(‘academic’,/*’adventure’,*/ ‘arts’, ‘religious’, ‘special-interest’, ‘special-needs’, ‘sports’,’teen’);//Must upate as new Main categories are added $out = array(); foreach($catslugs as $slug) { array_push($out, get_category_by_slug($slug)->term_id); $CatIDs= implode(‘,’, $out); } //featured category ID = 153 //academic category […]

WordPress custom taxonomy query

I have a custom post type (Media Articles) which uses some custom fields and has some custom taxonomies. I have no problem outputting all custom posts using a CPT archive template. I also have a menu in the sidebar of the various custom taxonomies I have registered for this CPT for the purpose of filtering […]

WordPress text field in array problem

This my code. $idsposts = solstice_get_opt(‘slider_4’); // example: 443,755,155,282 $myposts = array($idsposts); // must be array(443,755,155,282) but i saw array(443) $blog_featured_post_args = array( ‘post__in’ => $myposts, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ); What is my problem? This code get only 1 post (in example showing only 443 id […]

Efficient way of querying for a “fallback” post?

Is there a more efficient way of querying for a “fallback” post in case a post doesn’t have a meta key? I’m checking for the meta key featured-checkbox and if it doesn’t exist, I get the most recent post. But it seems messy. Is there a way to query for 2 posts in the first […]