Tag Info

New answers tagged

1

It is the output juggling that get_results() does. If you look at the source for get_results(), the work of the query is done by query(). Eveything after that is just "casting" the results to the data type specified by the $output argument. 1946 public function get_results( $query = null, $output = OBJECT ) { 1947 ...


1

The difference, if you want to call it that, is that the query() method is the general method to do queries with $wpdb, the get_results() method on the other hand is a specific method, which does make use of the query() method to retrieve the to this method specific results and than does some work on the output.


0

Great ! Awesome but there is single "(" bracket error in the above code in "Putting it all together" code block. while ( $custom_query->( have_posts() ) : it should be while ( $custom_query->have_posts() ) : i am using https://github.com/talentedaamer/Bootstrap-wordpress-pagination for pagination and it is working perfect. Thank you again.


0

Okay, it's not a simple array but a multi level array, so you can not simply use <?php echo $video->link; ?>. It wont print anything because $video array does not have any child item named link but link is the item of a child array. So if you are certain that you only need to get link value of first child array then use this. <?php echo ...


0

A working solution to help someone in the future: <ul id="filters"> <li><a href="#" data-filter="*">Everything</a></li> <?php $terms = get_terms("category"); // get all categories, but you can use any taxonomy $count = count($terms); //How many are they? if ( $count > 0 ){ //If there ...


0

Just add this before your code $authors = array( 1, 2, 3 ); // privileged users array $signed_in_user = wp_get_current_user(); // get current user // check if singed in user is in authors array if ( in_array( $signed_in_user->ID, $authors ) ) : And then this after your code <?php else : ?> This message will be displayed if the signed in user is ...


-1

add_filter( 'query', 'query_report', 10000 ); function query_report($sql){ var_dump($sql); return $sql; }


2

I don't think there's a way to do it without using filters. Using posts_clauses you could do: function wpse163696_posts_clauses( $pieces, $query ) { if ( $query->get( 'orderby' ) != 'dealer_date' ) { return $pieces; } global $wpdb; $order = $query->get( 'order' ); $pieces[ 'join' ] .= $wpdb->prepare( ' LEFT JOIN ...


0

Meta query must be done with a nested array. So it may look more like this: $query = new WP_Query( array( 'meta_query' => array( array( 'key' => 'duedate', 'value'=> $today, ...


1

You have a couple of errors there, I believe. 1) There is no such parameter as 'numberposts'. Perhaps you mean 'posts_per_page'? That is what you should use to determine the number of posts to display. 2) When ordering by meta value, the correct syntax should be: 'orderby' => 'meta_value', 'meta_key' => 'key_name', Where key_name is the custom ...


0

First of all, never use query_posts Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL ...


0

Use like this query_posts( array( 'category__in' => array(5,1), 'posts_per_page' => 1, 'orderby' => 'title', 'order' => 'ASC' ) ); or $my_query = new WP_query(array('category__and' => array(5,1))); while ($my_query->have_posts()) : $my_query->the_post();


1

I would recommend that you use WP_Query for this one: $categories = get_categories( 'child_of=83' ); foreach ( $categories as $category ) { echo '<h3>' . $category -> name . '</h3>'; echo '<ul>'; // create a WP_Query that retreives all posts from the specified // category which is older then 1 week $args = array( ...


1

First of all, never use query_posts Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL ...


0

You could do this in a few ways, below I've laid out two. Method 1: Modulus The idea is that you get the remainder of your $counter divided by $grids. In our case, the left side will always be counted as: 1, 4, 7, 10, etc. so the remainder of our $grid (being 3) will always be 1. Our last column will be always equate to 0. At the bottom we must increment ...


1

Try this: $categoria = get_the_category(); $objetoBase = new WP_Query('category__in='.$categoria[0]->term_id); In the codex you can find the example of category__in which will not show the children. Hope that works, Diogo


1

Just use the parameter category__in of WP_Query - if you do this, then there is no need for cat and category__not_in. category__in does give you back results from the categor(y/ies) specified, but does not include results for the children of the specified categor(y/ies).


0

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 ...


0

Why not just orderby your ShowPostByVotes query in the (1) custom query? Are they accessible to each other?


1

You can use the name parameter in your arguments ex: <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 12, 'name' => 'slug' ); but this will only match the post with that same slug.


1

I manage to work my problem. For those who seek the same answer, just run this query INSERT INTO wp_postmeta (post_id, meta_key, meta_value) SELECT wp_posts.ID, 'video_desc', 'Description here' FROM wp_posts WHERE wp_posts.post_status = 'publish';


1

Just to clarify the get_var() method of $wpdb does work just fine in this context: global $wpdb; $helloworld_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $helloworld_id; Actually it is more practical in this context, because a single variable is returned, which is what is actually wanted.


0

I found the solution and the correct query to fetch one data from WordPress database is below one. global $wpdb; $findID = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $findID[0]->ID;



Top 50 recent answers are included