Is there a better way to pull in custom content without querying posts?

It’s not a hack, this is what databases are designed for- querying large quantities of data. If you’re concerned about load, you should employ caching on data that doesn’t change frequently. That said, you should not be using query_posts to create additional queries. Really, you shouldn’t be using query_posts at all. Create additional queries via … Read more

How to order posts in an arbitrary order?

First off, query_posts is terrible doesn’t use it. It does all kinds of fun things like mess up the very useful conditional tags like is_singular and the like as well as mess up pagination. Short of hooking into the posts_orderby filter and writing some custom order by SQL, your best bet is to use the … Read more

Order posts alphabetically: how to set order=asc in mysql query?

Why don’t you use WordPress get_posts? You can add the parameter orderby => ‘title’ as you want. $args = array( ‘posts_per_page’ => -1, ‘order’ => ‘ASC’, ‘orderby’ => ‘title’ ); $posts = get_posts( $args ); print_r($posts); If you want the sql you can just add ORDER BY post_title: SELECT * FROM $wpdb->posts WHERE post_type=”post” AND … Read more

ACF: post query, hide duplicate values [closed]

You could pass all the fields into an array during your while loop, strip the array of duplicates, and then run a foreach loop on that array. It would look something like this: <?php $designers = array(); while ( $the_query->have_posts() ) : $the_query->the_post(); $designers[] = get_field(‘products_page_designer_name’); endwhile; // This will strip out any values that … Read more

Query Posts by Custom Field

You can achive this using WP Query with meta_query argument as following. $args = array ( ‘post_type’ => array( ‘post’ ), // YOUR POST TYPE ‘meta_query’ => array( array( ‘key’ => ‘country’, ‘value’ => $your_country, // THE COUNTRY TO SEARCH ‘compare’ => ‘LIKE’, // TO SEARCH THIS COUNTRY IN YOUR COMMA SEPERATED STRING ‘type’ => … Read more

How to display Related Posts based on number of taxonomy terms matched

Let’s split the problem up in three bits: retrieving the related posts from the database, sorting them and displaying the result. Post retrieval This is possible using the taxonomy parameters offered in WP_Query. Let’s first retrieve the category of the current post and find their IDs: $categories = get_the_terms( get_the_ID(), ‘news-category’ ); foreach ( $categories … Read more

pagination not working for category.php (custom post types in categories)

<?php $catname = wp_title(”, false); $wp_query = new WP_Query(); $wp_query->query(‘category_name=”.$catname.”&showposts=5′.’&paged=’.$paged); ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php the_title(); ?> <?php } ?> <?php endwhile; ?> <?php next_posts_link(‘&laquo; Older Entries’) ?> <?php previous_posts_link(‘Newer Entries &raquo;’) ?> I think that you need to look at the $paged variables.

Query all posts if multiple meta key don’t exist

global $wpdb; $excludeposts = “SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_status=”publish” AND meta_key NOT LIKE %aa_% ORDER BY post_date DESC “; $main_query = new WP_Query( array( ‘post__not_in’ => $excludeposts, ‘paged’ => $paged ) ); while ($main_query->have_posts()) : $main_query->the_post(); //Stuff… endwhile; //hope this helps

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