Tag Info

Hot answers tagged

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


1

If I was in your shoes, I'd use get_user_meta(). // get the users -- I'm ordering them by their username $args = array( 'orderby' => 'login', 'order' => 'ASC', ); $users = get_users( $args ); foreach( $users as $user ) { $user_meta = get_user_meta( $user->ID ); var_dump( $user_meta ); // to show you what you've got } This is a ...


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.


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

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

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


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

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


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

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



Only top voted, non community-wiki answers of a minimum length are eligible