wp-query

WP_Query orderby 'rand' not working

给你一囗甜甜゛ 提交于 2019-12-13 19:44:38
问题 Trying to order some posts I'm displaying on a single custom post type page with random, but they aren't random at all. :/ <?php // Grab the taxonomy term slug for the current post $terms = get_the_terms( get_the_ID(), 'category-staff' ); if ( $terms && ! is_wp_error( $terms ) ) : $draught_links = array(); foreach ( $terms as $term ) { $draught_links[] = $term->slug; } $on_draught = join( ", ", $draught_links ); ?> <div class="container hidden-xs"> <div class="row"> <div class="col-sm-12">

How to show data from database in wordpress?

落花浮王杯 提交于 2019-12-13 07:42:34
问题 I am trying to add following code in WordPress, but I cant find the right way to do it. Please help me someone... <?php include("config.php"); $results = $mysqli->query("SELECT COUNT(*) as t_records FROM wp_posts"); $total_records = $results->fetch_object(); $total_groups = ceil($total_records->t_records/$items_per_group); $results->close(); ?> It's work great nice if I use it outside of WordPress. But I don't know hot to implement this in my WordPress index.php There is a lot of code in my

fetch products if image is found in woocommerce?

对着背影说爱祢 提交于 2019-12-13 05:48:56
问题 i want to show image only products in woocommerce. My fetch query is given below $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 9, 'orderby' =>'date','orderby' => 'rand' ); $loop = new WP_Query( $args ); how can i get the image products only? 回答1: Are you looking for something like this ? <?php $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 9, 'orderby' =>'date','orderby' => 'rand' ); $loop = new WP_Query( $args ); while ($loop->have

Display multiple sets of content items a from a Wordpress query with javascript

你。 提交于 2019-12-12 02:44:40
问题 I am trying to get my recent posts to display in a fading content list with java-script. I want to pull 12 of the latest posts, and then display them, 4 at a time, from most recent to least. These are my query details: <?php $my_query = new WP_Query('showposts=12'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php if (strlen(the_title('','',FALSE)) > 80) { $title_short = substr(the_title('','',FALSE), 0, 80); preg_match('/^(.*)\s/s', $title_short, $matches); if ($matches[1])

How to paginate a custom WP_query() loop - Wordpress

只谈情不闲聊 提交于 2019-12-11 06:53:49
问题 I have a blog page that calls posts with tag 'blog'. So i called a custom WP_query() object: $blog = new WP_query('tag=blog'); . The result works fine, but when i paginate the posts, the links always is shown even if doesn't exist more than 10 posts (the default limit). How can i fix it? 回答1: just add the following code $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; then you query will be like as following $blog = new WP_query('tag=blog&posts_per_page=10&paged=' . $paged); 来源

combine keyword search and tax query in wp_query

末鹿安然 提交于 2019-12-08 07:24:46
问题 I've been trying to create a custom search query, and I've made some progress on it, but have hit another roadbump. I'm trying to combine the meta_query, keyword search ('s') and tax_query in a wp_query with an 'OR' relationship. I've gotten the meta_query and 's' to work together thanks to this fantastic post: https://wordpress.stackexchange.com/questions/99849/search-that-will-look-in-custom-field-post-title-and-post-content however, the tax_query is still giving me trouble. I tried adding

visual composer wordpress query for post grid

别来无恙 提交于 2019-12-08 04:58:59
问题 I am using visual composer by http://vc.wpbakery.com/ and when their post grid creator only allows you to use custom post types if you use a query. I have a simple query working: post_type=post_mission_trip&post_status=publish&posts_per_page=3 I need to create a more complex one that would do something like this: $myCompletedResearch = new WP_Query(array( 'post_type' => 'post_mission_trip', 'post_status' => 'publish' 'posts_per_page'=>3, 'orderby'=>'meta_value_num', 'meta_key'=>'trip_begin',

query_posts() should be avoided?

隐身守侯 提交于 2019-11-26 23:18:30
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() && $query->is_main_query() ) { $sort= $_GET['sort']; if($sort == "pricelow"){ $query->set( 'meta_key',