wp-query

How do i check if a wordpress query has more posts?

徘徊边缘 提交于 2020-01-14 03:42:08
问题 So i am using ajax to filter and load posts into a container. I want to limit the amount of posts to 6 at a time and add a load more button underneath if there are more than 6 posts, but i don't want to add pages because i have a few containers on the same page that i'm using this same treatment for and my understanding is pages would add a /page-1 or something like that to the url (am i wrong?). Either way, i just want to know how to check if there are more posts that fit this criteria so i

query_posts() should be avoided?

帅比萌擦擦* 提交于 2020-01-08 18:01:05
问题 I am reading that query_posts() should be avoided in favor of wp_query() and pre_get_posts() . I am not confident with messing with the Loop and do not fully understand the codex. Does the code below use query_posts() ? If yes and since query_posts() should be avoided, can you suggest a method that does not use query_posts() but still accomplish the same thing? This code in functions.php is used to sort posts by random or by price. function my_custom_query($query){ if ( $query->is_home() &&

Get all posts beginning with letter A

浪子不回头ぞ 提交于 2020-01-06 03:10:28
问题 How can i get all poasts beginning with the letter A (in the post_title)? My idea was to use regex but this code dont work. $my_custom_query_args = array( 'cat' => '1', 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 25, 'offset' => 0, 'value' => '^'.$letter.'', 'compare' => 'REGEXP' ); 回答1: Using post_where , this action code be use in custom template. add_action( 'posts_where', 'startswithaction' ); function startswithaction( $sql ){ global $wpdb; $startswith = get

WP Query taxonomy.php to display posts from current term

前提是你 提交于 2019-12-25 17:14:34
问题 I am using the following wp_query within my taxonomy.php file to try and display the list of posts from within a term from that taxonomy. I also have 6 taxonomies that I would like this to apply to, and so I would like to make the $args 'taxonomy' => 'topic' and 'terms' => 'arabisation' dynamic, to relate to the current page the user is viewing. Thanks <?php get_header(); ?> <?php get_sidebar(); ?> <section id="hero-image"> <div class="gradient-overlay"> <?php // vars $queried_object = get

Pull in previous and next post featured images into single.php

大憨熊 提交于 2019-12-25 04:47:08
问题 My previous and next posts are set on an infinite loop so there is always a previous and next post. I.E. for the newest article the "next" post would be go to the oldest post. And if we're viewing the oldest post, the "previous" post would go to the newest post. I need to pull in the featured images of the next and previous posts to be the background for the pagination navigation. I've got the images pulling in when there truly is a next or previous post. However, when the infinite loop is

Wordpress: Dynamically query/filter posts by taxonomy term_id

◇◆丶佛笑我妖孽 提交于 2019-12-25 01:42:04
问题 I have a walker to display terms of a taxonomy (see post here). It's a hierarchical list that is 3 levels deep: Taxonomy terms (number of posts incl. all sub levels) 1.1. subterms (number of posts incl. subsubterms 1 & 2) 1.1.1. subsubterms (number of posts) display post with Category "Subsubterms" 1.1.2 subsubterms (number of posts) display post with Category "Subsubterms" The terms display fine, but the posts on subsubterm-level do not display. The following code only displays post from the

Loop for a specific category for homepage

梦想与她 提交于 2019-12-24 07:29:43
问题 For my homepage I want to display posts for a specific category (for example category "food") instead of the default display of all posts. How can this be accomplished? Is it true that I am supposed to use wp_query() and avoid query_posts() ? Also, will I need to reset with wp_reset_postdata(); for this loop in index.php ? I have read codex and googled around, but still am not confident with altering the Loop. I thought the code below would work but I get White Screen of death in WordPress

WP_Query returns no results

独自空忆成欢 提交于 2019-12-24 03:34:27
问题 I am trying to retrieve some pages in wordpress using WP_Query and some arguments: $args = array( 'post_type' => 'posttype', 'posts_per_page' => 24, 'post__in' => $store_ids, 'paged' => $paged, 'post_status' => 'publish', ); $the_query = new WP_Query( $args ); The pages I'm trying to retrieve here should match an ID in an array of ID's I have given it. The array and other arguments seem fine since I do get my results when I use get_posts instead of WP_Query . What is going wrong here? 回答1: My

WP_Query same request, different syntax - one of which does not work

本小妞迷上赌 提交于 2019-12-23 12:37:05
问题 I have a WP_Query which works well: $args = array( 'post_type' => 'product', 'meta_key' => 'product_subtype', 'meta_value'=> 'public', 'compare' => '=' ); but as I want to search for multiple meta_keys, I tried the 'array'-syntax: $args = array( 'post_type' => 'product', 'meta_query' => array( array( 'meta_key' => 'product_subtype', 'meta_value' => 'public', 'compare' => '=' ), ), ); but it does not work - it gives me all the posts with 'post_type' = 'product' - although it is the very same

I need filter content of posts accoring to post title and meta value

眉间皱痕 提交于 2019-12-14 00:02:20
问题 I have applied following code. $postcode = $_POST['postcode']; $title = $_POST['term']; $args = array('post_type' => 'product','meta_query' => array( array( 'key' => 'custom_field_ID_1','value' => $postcode,'compare' => 'LIKE' ))); $the_query = new WP_Query( $args ); echo"<pre>";print_r($the_query);echo"</pre>"; But showing result according to meta value not for post title. Please let me know solutions... 回答1: you can use post title into wp_query by adding this to functions.php file: add