Tag Info

New answers tagged

1

I don't think there is a parameter value Today as you used in date_query. If you want to return today's post then you should provide date value to date_query as you stored current date in $today array. So here is your query now. $today = getdate(); $args = array( 'tag_slug__in' => array( 'destacado'), 'posts_per_page' => ...


-1

Try replacing getdate() with current_time('Y-m-d')


1

You have two issues here. The use of $image->ID in this line wp_get_attachment_image($image->ID, 'video-thumb'); This will give you the following error: NOTICE Error: [8] Undefined variable: image In all honesty, I think that should actually be $post->ID get_permalink() returns the permalink to the current post, which in this case ...


0

Create file called taxonomy-industry.php and copy your archive.php into it. I faced the same proplem with my site and that solution worked for me. Hope it works for you


0

The issue appears to have resolved itself I had some custom permalink function rewriting %industry%, which I had tested and verified wasn't the problem. I changed its code and changed it back again, and the site works as expected now. I'm confused, but mostly satisfied.


0

You can get same result by outputting values from PHP array. Since it is multicolumn array, you will need to run foreach loop and get values of each child item. Mostly it's standard PHP stuff, nothing special. Although earlier you did not need to supply post ID in each WordPress function since you were using it inside a loop, but now you will have to do ...


0

For multiple meta value you have to use "IN" $args = array( 'posts_per_page' => -1, 'post_type' => 'shows', 'orderby' => 'meta_value_num', 'meta_key' => 'start_date', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'show_location', 'value' => ...


1

On the advise of Robert and Pieter I rewrote the loops using WP_Query instead of query_posts. It works now. Thanks guys. Here's the code: <ul class="tabs"> <li class="tab-link current" data-tab="tab-1">Most Popular</li> <li class="tab-link" data-tab="tab-2">Recent</li> ...


-2

Try fetching as $_GET['category']. Then u can use it whichever way u like


3

See the codex re Meta Query. For example, this would get all posts at least a day old: $date = date('Y-m-d H:i:s',strtotime("-1 days")); // 1 day ago meta_query' => array( array( 'key' => 'name of your key', 'value' => $date, 'compare' => '<=', 'type' => ...


2

In the dump of your $args above, nopaging is set to 1 which disables pagination (equivalent to posts_per_page = -1). Try setting this to false and see if it fixes your issue. You can then look into why it's being set.


0

You can use a conditional tag with the pre_get_posts action hook like this from your functions file. add_action( 'pre_get_posts', 'vm_get_shows' ); function vm_get_shows ( $query ) { if ( !is_admin() && $query->is_main_query() && is_home() ) { $query->set('post_type', 'shows' ); } }


0

Here is a slight variation of an answer I have done on about the same scenario. What differs here is that you want less posts_per_page on page one STEP 1 Remove query_posts. You should never ever 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 ...


-1

Try this code here <?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; if($paged == 1){ $posts_per_page = 100; }else{ $posts_per_page = 300; } query_posts( array( 'posts_per_page' => $posts_per_page, 'post_type' => array( 'regularproducts', 'wpsc-product' ), 'paged' => $paged, )); ?>


5

By default, WP_Query returns the standard WP_Post objects for the posts being queried. I believe with some clever rewrite and use of the filters given in WP_Query you can add objects to the returned WP_Post objects array. Will this be performant. In my opinion, I will hurt performance more as you will need to join results in your query as custom fields are ...


0

Hey Please try this one I think it work fine. $args = array( 'post_type' => 'page', 'meta_key' => 'someMetaKeyName', 'meta_query' => array( array( 'key' => 'someMetaKeyName', 'type' => 'CHAR', ), ), ); ...


1

If you're trying to get all meta values for a key within a specific post type, you can do something like this in a single query: SELECT post_id, meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = 'sd_rating' and pm.post_id = p.ID AND p.post_type = 'cpu'


1

I have found a way : global $wpdb,$post; $query_ids = $wpdb->get_results("SELECT ID FROM ".$wpdb->prefix."posts WHERE (post_type = 'cpu') LIMIT 0,10"); foreach ($query_ids as $query_id) { $query = ...


0

Are you using a checkbox or similar for the 'acf_platform' field using ACF for more than one selection? Advanced Custom Fields stores these as a serialised array, so a meta_query with 'compare' => '=' may not work. The ACF documentation suggests using 'compare' => 'LIKE' $args = array( 'meta_query' => array( array( 'key' => ...


0

Here is an idea. Note, this will only work if all posts are in the desired category and if all posts have only category The posts are returned in an array which you can access through $currentissue->posts With this in mind, you can get the first post ID as follows $currentissue->posts[0]->ID Now, you can add that to a variable $id = ...


0

When you set up your query, do it this way ( I believe you were missing the 'date_query' key ): $args = array( 'date_query' => array( array( 'year' => 2012, 'month' => 12, 'day' => 12, ), ), 'ignore_sticky_posts' => true, 'post__not_in' => get_option('sticky_posts') ...


1

The Transients API is similar to the Options API and that means as of right now, unless they make a change in v4.1 or the future release, all of your transients are going to be moving in and out of the tableprefix_options table. If your website is busy, that means your going to have a ton of reading & writing taking place which defeats the purpose of ...


1

The rule of thumb is not to do any caching, except for object caching, for logged in users. Actually IIRC object caching will give you exactly what you want. But if you have to do it your way, you should make your cache keys to be based on the query and have different cache for different queries. A similar but maybe easier to grasp idea is do "group" users ...


0

Instead of using posts_where it is a better idea to use pre_get_posts filter. Here is the code I end up implementing: add_filter( 'pre_get_posts', 'hide_unwanted_posts_filter' ); function hide_unwanted_posts_filter( $query ) { global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; $key = 'unwanted_posts'; ...


2

As you might or might not know, the main query uses WP_Query, the only difference from a custom query as in your question is that the main query parses the URL to get the paramaters and arguments passed where a custom query uses user defined parameters and arguments. The main query and any new instance of WP_Query returns exactly the same array of results ...


3

The problem with accessing post content directly is that you lose the filters. Whether that matters depends on the context. If you're building a theme for distribution, you always want to use the API over directly accessing objects.


2

All 3 of these could do the same thing, it's just a matter of how you want to use them. the_title() calls get_the_title() which gets the title by $post->post_title. View the_title() Source on Trac View get_the_title() Source on Trac Personally, I would never use choice 3 as from a readability stand point it's not the most obvious what it's doing. On ...


0

Why don't you directly echo the $num as it will contain the count of rows already...Here's the edited part.. //To show number of rows in table function DB_Tables_Rows() { global $wpdb; $table_name = $wpdb->prefix . 'mydata'; $count_query = "select count(*) from $table_name"; $num = $wpdb->get_var($count_query); echo $num . ...


0

WAY #1 You can use the WordPress way using $wpdb class: <?php global $wpdb; $table_name = $wpdb->prefix . 'mydata'; $my_query = $wpdb->get_results( "SELECT * FROM $table_name" ); echo $wpdb->num_rows; The codex says: Since this function uses the $wpdb->query() function all the class variables are properly set. The results count for a ...


1

Nested relations among subset of meta queries are possible on WP 4.1 that is planned to be releaded next coming December 10, 2014. See trac ticket. So wait a few days or use the beta version.


-1

What if you save each query in a variable ? <ul> <?php $query1 = query_posts( array( 'posts_per_page' => -1, 'post_type' => array('specialties') )); if($query1->have_posts()): while($query1->have_posts()): $query1->the_post(); ?> <li> <!-- title from post type specialties --> ...


0

OK, After a lot of trial and error and asking around I managed to finally get a working solution. Thought I would post it here for those that are trying to fix a similar problem in the future. Filter 1: posts_join creates a left join on all queries to link up the postmeta table. Its important to note that I have created the postmeta table with an alias of ...


2

Unfortunately, you can't. At least not with a single WP_Query, that is. What you could do, however, is run two separate queries - one for each post type - then combine the results. Like so: $args = array( 'post_type' => 'image', 'category_name' => $cat, 'meta_key' => 'total_votes', 'orderby' => 'date ...


-1

function title_filter( $where, &$wp_query ) { global $wpdb; if ( $search_term = $wp_query->get( 'search_prod_title' ) ) { $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( like_escape( $search_term ) ) . '%\''; } return $where; } function get_my_suggestions() { $search_term = $_GET['term']; $cat ...


0

Please use the following code: $arg = array ( 'posts_per_page' => get_option('posts_per_page'), 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ); $wp_query = new WP_Query($arg); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); // do something endwhile; ...


0

The final working arguments: <?php if( isset( $_GET['Price'] ) ) { $meta_array[] = array( 'key' => 'price', 'value' => esc_attr($_GET['Price']) // 'compare' => '=' ); } if( isset( $_GET['Region'] ) ) { $meta_array[] = array( ...


3

It depends on local factors and actual usage patterns. Bigger queries require more memory to store the data and potentially, depending on the plugins you use, to process it into the response, therefor you are more in a risk of running out of memory. With Bigger response (i.e. bigger page HTML) it takes more time to transfer the page to the browser making the ...


0

Finally I got the code. Using below code, you can pick your OnSale products that are either Simple Product On Sale or Variable Product On Sale. Keep in mind that this code will pick every post in which you added sale price in the below image mentioned column . So avoid adding the price in this column (Shown in attached Image) if your sale price is same as ...


0

I ended up doing this - works perfectly. <?php $argsb = array('posts_per_page' => -1, 'post_status' => 'publish');?> <?php $blog = new WP_Query($argsb); if ( $blog->have_posts() ): ?> <section class="blog-slider slider"> <div class="flexslider"> <ul class="slides"> <?php while ( $blog->have_posts() ) : ...


0

I have solved my problem and it had nothing to do with the query, the database or the post type. The problem was that in trying to initially construct the query I had left a pre_get_posts function in my functions.php which was conflicting with my query. The lesson here for me is to make sure I have thoroughly checked ALL files. The offending counter code: ...


0

You need a loop within a loop - loop through a counter, and for each value, check for the existence of each key with the current counter value appended. // max custom field index $number = 40; // the counter $counter = ''; // the meta keys to check for $keys = array( 'custom_text', 'custom_image', 'custom_video' ); // all our custom field values ...


1

I'm posting a new answer because I found this thread while searching for the same thing and the solutions here weren't optimal. The post_type argument can be a string or an array of post types. function custom_count_posts_by_author($user_id, $post_type = array('post', 'page')) { $args = array( 'post_type' => $post_type, 'author' ...


0

Sorry for answering my own question but it may help some other devs too. I created this additional filter 'json_query_var-meta_query'that returns the necessary arguments. function adjustQrry($data){ $args = array(); $args['relation'] = 'AND'; foreach ($data as $key=>$value) { if ( 'relation' === $key ) { ...


0

Switching out echo get_comments_number($post->ID) for echo $post->comment_count did the trick. I have no idea why, that's exactly what the get_comments_number() function does...


1

You can modify search query and set your parameters with the help of pre_get_posts. Like this. function wpse_custom_get_posts( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search() ) { $query->set( 'post_status', 'publish' ); } } add_action( 'pre_get_posts', 'wpse_custom_get_posts', 1 );


-2

You can also use this method.. $total_comments = wp_count_comments( $post_ID ); echo "Total Comments: " . $total_comments->total_comments;


-3

$current_post_comments_count = get_comments_number( $post_id ); You can use this.


0

Instead of that try using; <?php get_userdata( $userid ); ?> For example; <?php $user_info = get_userdata(1); // get info for user id '1' $username = $user_info->user_login; $first_name = $user_info->first_name; $last_name = $user_info->last_name; ?> For more details visit this link.


0

Because I am a complete idiot, I seem to have completely forgotten that I basically answered my own question over a year ago. I was struggling to get the posts_join filter to behave (I generally have trouble with INNER JOINs anyway), and so instead looked to the posts_where filter. The main issue with it is that you can't pass any arguments to it other ...


1

The answer from the OP inspired me to quickly write this function which is not resource intensive and really fast. I also decided to try another method as described by the OP To accomplish this, I've made use of the Transient API and the post_updated action THE LOGIC To get the position of a post, you will first need to get all the posts and determine ...



Top 50 recent answers are included