Hook to get the query result after listing posts

Hook to get the query result after listing posts Use the loop_end hook – it passes the WP_Query by reference. add_action( ‘loop_end’, ‘wpse_263822_loop_end’, 10, 1 ); function wpse_263822_loop_end( $query ) { //* Make sure we’re in the loop if( ! in_the_loop() ) { return; } //* Do something useful with the WP_Query print_r( $query->posts ); … Read more

How to handle wp_query?

You’re not showing your entire code, so not all of these suggestions may be relevant: Use distinct, ideally descriptive, names for the variables that hold the different queries. Using the same variable, $my_query, can lead to unintended consequences. Be sure to close the first loop properly, with endwhile; endif;, before opening the second loop. Be … Read more

Can’t get LIKE to work with wp_query [closed]

When you set up the meta_query value like: ‘value’ => “‘” . $city . “‘”, it gets translated to LIKE ‘%\’ondon\’%’ in the final SQL query, which matches things like L’ondon’ or L’ondon’er but not London. But you actually want it to be like: LIKE ‘%ondon%’ – so you should do: ‘value’ => $city, EDIT … Read more

How can I echo out the user id in user meta?

If you want to display the info on the current user logged in you can use get_currentuserinfo. [Codex] Example from Codex <?php global $current_user; get_currentuserinfo(); echo ‘Username: ‘ . $current_user->user_login . “\n”; echo ‘User email: ‘ . $current_user->user_email . “\n”; echo ‘User first name: ‘ . $current_user->user_firstname . “\n”; echo ‘User last name: ‘ . … Read more

Pagination on custom post type not working

Fixed it by changing the page’s name (more so the page’s URL) so that it did not match the post type name, which causes rewrite problems. I also learned that previous_posts_link(); and next_posts_link(); as well as wp_paginate() rely on the query variable being named “$wp_query”, so “$my_query” doesn’t work. Here’s my fixed code: if ( … Read more

Incorrect posts displayed on category page

First of all, never ever make use of query_posts. It is not just slow and reruns queries, but it breaks pagination, page functionalities and the globals like $post on which some theme functionalities and plugins rely. If you really need to run custom queries (which is totally unnecessary in this case), make use of WP_Query … Read more

query_vars category_name only display one catgory out of multiple categories

Inside get_posts() of WP_Query class, you will see this code block. /* * Ensure that ‘taxonomy’, ‘term’, ‘term_id’, ‘cat’, and * ‘category_name’ vars are set for backward compatibility. */ if ( ! empty( $this->tax_query->queried_terms ) ) { /* * Set ‘taxonomy’, ‘term’, and ‘term_id’ to the * first taxonomy other than ‘post_tag’ or ‘category’. */ … Read more

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