Sort order in get_posts [closed]

The problem here is not that the posts that are being wrongly displayed are displayed under the wrong category, it’s that they’re not actually in the right category. For example, the post “Supporting healthy eating choices” is displayed under “O” as it has the category “O”. Going to your backend and assigning the proper category … Read more

excludeCat function reverses order of blog posts

function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-5377’ ); $query->set( ‘orderby’, ‘date’ ); $query->set( ‘order’, ‘DESC’ ); } } add_action( ‘pre_get_posts’, ‘exclude_category’ ); Use ASC or DESC for order. Add code to child themes functions file. Tested and works.

search.php is not generating the right results

Try adding the following code to the top of your search.php template below the get_header() call: <?php global $query_string; $query_args = explode(“&”, $query_string); $search_query = array(); foreach($query_args as $key => $string) { $query_split = explode(“=”, $string); $search_query[$query_split[0]] = urldecode($query_split[1]); } // foreach $search = new WP_Query($search_query); ?>

Apply ordering args to newly merged queried

Here’s what I’d do. This is mildly tested. It gets the IDs of all the posts you need and then builds a single query to get the posts in the correct order. // get your page IDs, I assume this returns an array of integers $page_ids = get_pageslug(” ‘first_page’, ‘second_page’ “); // get your blog … Read more

Update vs Insert logic but the last key is always inserted?

Ok here’s my altered function but this one doesn’t work at all but maybe you can see wher i go wrong function insertUserShoppingMetaData($params) { global $wpdb; $shopping_meta_table=”wp_shopping_metavalues”; $wp_user_id = $params[‘wp_user_id’]; $checkKeyValues = $wpdb->get_results(“SELECT meta_shopping_key FROM $shopping_meta_table WHERE wp_user_id = ‘$wp_user_id'”); //print_r($checkKeyValues); foreach ($params as $key => $val) { foreach($checkKeyValues as $check){ //UPDATE OR INSERT if … Read more

How to display a specific category using a custom Query in WordPress?

Why are you using $wpdb to query from database. Use WP_Query or get_posts instead. This is how you can query from WordPress database and get 4 latest posts from category id 24. <?php $args = array( ‘post_type’ => ‘post’, ‘cat’ => 24, ‘posts_per_page’ => 4, ‘ignore_sticky_posts’ => 1 ); $my_query = new WP_Query( $args ); … Read more

Using cron for multiple queries

It sounds like what you really might want is a transient. WP Transients are a way to cache the results of a query, and set an expiration date on that cache. So you could cache the results of your example from above for 24 hours. If anyone requests that data while the cache is still … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)