Questions tagged [query-posts]
Set up The Loop with query parameters. This will override the current WordPress Loop and shouldn’t be used more than once. This must not be used within the WordPress Loop.
1,241
questions
0
votes
1
answer
1k
views
Getting all ID's matching a title in a custom post type
I am trying to pull out all post ID's that have the same post title. This is in a custom post type called 'course-manager'. Here is what I have so far:
$pages = array();
$args1 = array(
...
1
vote
3
answers
3k
views
Loading post content in FancyBox
I got a tricky question. I have created a custom post type whose posts I would like to display in a scrolling carousel. The carousel will only display the title, the excerpt and a "read more" button. ...
1
vote
1
answer
280
views
Order query using custom meta data
I have created a custom post type called Events with the name of events
function add_events_post_type() {
register_post_type("events", array(
"label" => __("Events"),
...
1
vote
1
answer
80
views
Have parent category contain only one post?
Projects <-contains basic info about projects
-Proj1 <-detailed info about proj1
-Proj2 <-detailed info about proj2
-Proj3 <-detailed info about proj3
I have a post attributed to the ...
0
votes
4
answers
11k
views
query_posts() - problem with "s" parameter
I'm trying to create a search page for a custom post type. This is the code I'm using:
$s = $_GET['s'];
$args = array(
'post_type' => 'companies',
's' => $s
);
...
0
votes
1
answer
27
views
Post not found when filtered by category ID
On my home page I am trying to filter by a category type and limit it to one post; but I keep getting "no posts found". Here is my following code:
<?php query_posts('cat=34&showposts=1'); ?&...
1
vote
1
answer
1k
views
Query Custom posts of same taxonomy as the post itself
I have 2 custom post types: "Services" and "Works" and they both have a same taxonomy 'Genre'. Now the taxonomy 'Genre' has as term called 'novice'. 5 Recent posts under "Works" which has the term '...
0
votes
1
answer
234
views
Having trouble using this post category query on multiple pages?
I have three pages on my site (Listen, Read, Watch) which each query a different post category: "listen", "read", and "watch" respectively. I created three separate php files with their own unique ...
1
vote
1
answer
680
views
Display posts with tag that matches current post title
How would I show posts that have a tag who's name matches the title of the current post?
For example if you are on a post called "Hippo" at the bottom of the page I would like posts with the tag "...
1
vote
1
answer
625
views
Sorting multiple custom post types without a meta key/value pair by sort order
At this current moment. is it possible to sort multiple custom post/page types without a meta key/value?
I'm looking to just sort the posts by page attribute order:
What have i done so far? I've ...
0
votes
2
answers
109
views
Least Number of Loops to Create Custom Homepage?
I am trying to create a custom homepage where the site content is shown as follows...
See image...
https://i.stack.imgur.com/ykrdf.png
With separate loops this is simple... 3 individual query_posts ...
7
votes
4
answers
10k
views
How to query post by user role?
I want to query posts by their author role. And do something with the post based on the role.
I know we can get the post by get_posts or WP_query, the problem is there are no argument to sort the ...
0
votes
1
answer
14k
views
Add AJAX "Load more" on custom query block
I have a index,php with various new WP_Query all working ok, but in this block I need to implement that "AJAX thing people love - the load more posts":
<h2>Latests articles <?php ...
0
votes
1
answer
566
views
Query Posts to fetch Posts with Unique Tag
I am trying to write a query post such that it returns a list fixed list of posts from a category along with any of the one tag associated with it. For eg:
<?php $arg = array('cat' => '1','...
0
votes
1
answer
173
views
Exclude All Posts Which Do Not Have A Tag Assigned
Basically I have regular Category Listings that include posts WITH tags and posts WITHOUT tags.
I need to modify the loop so that it ONLY includes posts which have one or more tags assigned to them.
...
2
votes
6
answers
13k
views
Order posts by custom field and if custom field is empty return remaining posts
I have an archive page ordered by a numeric value in a custom field. This returns the ordered posts correctly, but does not display posts that don't have a custom field.
$paged = (get_query_var('...
1
vote
2
answers
205
views
Why is querying posts messing up my pages?
I am working on a theme at the moment and I have set up a post template.
This post template is linked to some custom post types.
When I query_posts for my post type on the actual post template ...
4
votes
1
answer
3k
views
Determine if more posts are available than was asked for in `query_posts()`?
I'm getting products (from a specific category) using a custom query_posts() function. I limited the showposts parameter to 25, so how do I know to activate pagination if there are still products (...
0
votes
1
answer
92
views
Change content off every sixth element
I would like to create custom post query where i will list all my posts in the list. Then the tricky bit is to add different content to sixth element off that list.
So something like this
<li>...
0
votes
3
answers
172
views
Weird problem on if statement
I'm facing a weird issue trying to do what I'm going to explain now.
Context
Plugins I'm using: Custom Post Type UI / Advanced Custom Fields
Functionality:
I have a custom post type called "vendors"...
0
votes
1
answer
1k
views
How to make WP_Query not to show irrelevant posts?
I'm using the following WP_Query arguments array:
$args = array( 'post_type' => POST_TYPE,
'tax_query' => array(
'taxonomy' => ...
0
votes
1
answer
3k
views
Posts limit on homepage (genesis framework)
in home.php
// NOT working
query_posts('show_posts=3');
// NOT working
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
$query->set( '...
0
votes
1
answer
596
views
Sticky posts don't show up first in custom loop
I'm using the following query in my frontpage template:
<?php $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args=array(
'paged' => $...
1
vote
1
answer
6k
views
Filter query_posts by tag slug on "Tag Archive" page (when tag is 2 or more words)
I'm using the following to bring up a tag archive page:
<?php query_posts( "tag=". '' . single_tag_title( '', false ) . '' ); ?>
This works perfectly for all tags of one word only, but any ...
0
votes
2
answers
1k
views
query_posts pagination will always show identical content
Anyone here see why my pagination won't work? I can get "previous page" to show up, but when navigating to "page-2", the content will stay identical to the content on "page-1".
<?php
/*
Template ...
3
votes
2
answers
48k
views
query_posts doesn't order by title
It seems like stupid bug, but how can i order by title? It anyways orders by date! I'm using:
query_posts( array(
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' ...
2
votes
1
answer
2k
views
How to Loop within a Loop (Display Children and then Grandchildren)
I am trying to develop a query for WordPress that will allow me to display a list of child pages with titles only, and then under each child page title, a list of grandchilden (children of the child) ...
1
vote
1
answer
26k
views
Multiple post type queries (with specific arguments for each)
So i know how to combine post types into 1 loop and out put the loop. Below is what i have:
<?php
$args = array(
'post_type' => array('post','movie','actor'),
...
0
votes
2
answers
6k
views
Exclude current post ID from loop in sidepbar.php
Currently all the below bit of code is doing is showing 3 random posts from the same category that the current page resides in. So if the current page falls in the artists category, for example, show ...
1
vote
2
answers
815
views
Query last updated posts (posts updated in the last 24 hours)
I'm having some difficulty to find an example of how to create a loop with posts that had been updated in the last 24 hours.
My idea is to have a page of posts or perhaps on the index.php a lists of ...
0
votes
1
answer
1k
views
orderby not working for query_posts using array of IDs
I have an array of IDs that i send to query_posts to get the posts (which works fine) but it seems to always put the attachment(562) last even though it is the newest. Also tried title and ASC vs DESC ...
1
vote
1
answer
2k
views
order posts by meta value on posts page
I've been reading alot about how to order posts by a meta_value, but I can't seem to get it to work for me.
My meta_key is called date, and it is stored as yyyy-mm-dd.
Here's where I've gotten to so ...
6
votes
2
answers
4k
views
Custom search filter causes menu and query_posts problems
I'm using a custom search filter (using my custom query var type), like so:
function fteh_pre_get_posts( $query ){
if( isset( $query->query_vars['type'] ) )
$types = explode( ',', $...
0
votes
1
answer
205
views
why is the current page title being output?
this is in my sidebar.php file, which is pulled in in the header.php file (is this bad practice?). anyways, the last item in the list is the current page title, despite my query_posts with an args of ...
0
votes
1
answer
204
views
Question about querying posts
I have this code on a query I'm doing
<?php query_posts('post_type=vendors'); ?>
<?php while (have_posts()):the_post(); ?>
<?php
$featured = get_field('promote_to_homepage', $post -&...
3
votes
2
answers
8k
views
List posts by category exclude current post
I'm trying to get a list of posts from one category, echo the title and the permalink of all posts on that category but exclude the permalink and the post name IF the current post is on that list.
It ...
1
vote
1
answer
1k
views
Displaying terms based on loop posts?
I have a shortcode that shows a loop for a custom post type:
while ( $loop->have_posts() ) : $loop->the_post();
// do something
endwhile;
Some of the posts are in categories ($term->...
0
votes
1
answer
62
views
Help in query for list links
How to make one query for display a list of links like this:
Date 05/20/2012
Category - Link
Category - Link
Category - Link
Category - Link
Category - Link
Date 05/19/2012
Category - Link
Category -...
2
votes
4
answers
5k
views
Unable to display multiple post types in same query (WPML WP_Query)
I'm sure there's some very easy explaination for this, but I'm stuck. I am just trying to put a nice, simple recent posts element on the front-page of a site and for some reason when I try to use:
$...
1
vote
3
answers
4k
views
query_posts and pagination, still stuck after much research
I need to paginate some custom posts...I can’t see why but I’m getting 404’s when going to the next page. Here’s my code:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( ...
0
votes
2
answers
996
views
How to only publish posts with image in it
I use a standard loop in my index.php and that shows all the posts beeing posted. What i'm looking for is a code that only shows the posts that have image(s) in it.
With other words: i only want to ...
2
votes
2
answers
1k
views
How to get 4 Posts after the 5 most recent ones
Well, I think the question might be a bit confusing. But well, I want to get the recent 4 posts, ignoring the first five recent posts. So in short the sixth, seventh, eighth and ninth - most recent ...
1
vote
1
answer
3k
views
How to make multiple sections in home pulling posts category wise?
This question may look foolish to everyone or novice , but i am working on a theme . It will be basically a news publishing theme .
Right now , In my home page all posts are showing one after ...
2
votes
1
answer
3k
views
Sorting Posts Via Custom Taxonomy Values Using Checkboxes?
I am working on a project that has a dropdown of custom taxonomy values called "Disciplines", there are only 4 of them in the dropdown. The way it has been designed is that you can select more than ...
15
votes
3
answers
76k
views
How to get posts published between a date and today?
Is it a way to get posts published between a date and today with query_posts() ?
Example : All posts published since 2012-04-01
Thanks
EDIT :
How to add the filter date on this Query Posts ?
...
0
votes
1
answer
2k
views
How to write sql query to get the posts from a custom taxonomy term name
I hope someone will help me.............
I have a
Post Type ----> Dealers
Taxonomy ----> State
how to write a sql query in this format
$catinfo1 = $wpdb->get_results("select t.*,(select count(...
0
votes
2
answers
185
views
Currently using a query_posts() in my theme - want to use a request filter in stead
I am currently using this code in my theme right before showing the content of the custom post type my_post_type:
$title = $post->post_title;
query_posts( array (
'post_type' => 'page',
...
1
vote
1
answer
818
views
Get latest 3 posts from multiple CPT in one query
I'm looking to create a site wide feed on my site and have multiple custom post types. I'd like to display say 3 posts from at least 3 different post types. I can get the latest 10 posts across each ...
2
votes
1
answer
12k
views
Query only Posts from Both of Two Category?
I have 3 categories,
1.OnGoing projects(cat id='5')
2.Completed Projects(cat id='6')
3.Upcoming Projects(cat id='7')
and also i have another 2 categories:(Not a Sub Category)
chennai (cat id='10')...
2
votes
1
answer
7k
views
Retrieve or Query Pages by ID
I have a problem with my code, I want to display 3 specific pages on my homepage but my code is not working.. here's the code..
<?php $args = array(
'post_type' => 'page',...