Custom search SQL Query to add custom field in result

I got it ! Here is my final code for people who will search for similar problem 🙂 in functions.php : function se190254_custom_sql_for_search( ) { global $wpdb; //For security escape the search parameter $search_string = esc_sql($_GET[‘s’]); //Build the SQL request with $wpdb->base_prefix for “portability” $sql = “SELECT SQL_CALC_FOUND_ROWS {$wpdb->base_prefix}posts.ID FROM {$wpdb->base_prefix}posts LEFT JOIN {$wpdb->base_prefix}icl_translations t … Read more

Dynamic category name in query post

You shouldn’t use query_posts functions. You should create instance of WP_Query class In your theme folder create a new file called category-slug.php. You can copy the category.php file or archive.php file to create category-slug.php file. Then in the new category-slug.php file before the while loop you can write your query. $query = new WP_Query( ‘category_name=apple,pears’ … Read more

Make tag archive display post are ordered by post format

You’re right. It isn’t a good structure. You are running three queries on the page– the two you are creating plus the main query that is being completely ignored (plus ancillary queries). You are also clobbering the main query halfway through the page load when you overwrite $wp_query, which can cause unexpected and unpredictable results … Read more

How exclude 3 latest posts of a category in query_posts

I’d do it like this: $excluded_posts = array(); // select first 3 featured posts ordered by date $args = array ( ‘post_type’ => array( ‘post’ ), ‘category_name’ => ‘featured’, ‘posts_per_page’ => ‘3’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘ignore_sticky_posts’ => true, // or maybe not? ); $query = new WP_Query( $args ); while ( $query->have_posts() … Read more

WP-API: get posts in multiple categories

Assusming you are using V1 of the WP-API, did you tried the following endpoint: http://www.example.com/wp-json/posts?filter[category_name]=pink+warm I’m looking at the code in WP_JSON_Posts class and the get_post() should be able to handle that use case. UPDATE: It seems there is a limitation with the way the query is built. Here is a potential workaround: add_filter(‘json_query_var-category_name’, function( … Read more

How to reverse post navigation at bottom of post

You need to swap their arguments & rel tag too: <?php echo str_replace( ‘rel=”next”‘, ‘rel=”prev”‘, get_next_post_link( ‘%link’, _x( ‘<span class=”meta-nav”>&larr;</span> %title’, ‘Previous post link’, ‘twentythirteen’ ) ) ); ?> <?php echo str_replace( ‘rel=”prev”‘, ‘rel=”next”‘, get_previous_post_link( ‘%link’, _x( ‘%title <span class=”meta-nav”>&rarr;</span>’, ‘Next post link’, ‘twentythirteen’ ) ) ); ?>

Pagination, query more pages at once

offset would skip posts, it sounds like you want the current page number * the number of posts per page- $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $posts_per_page = $paged * get_option(‘posts_per_page’); $args = array( ‘posts_per_page’ => $posts_per_page ); You’ll need to keep in mind that total number of pages in the query object will … Read more

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