Problem in exploding the_content to array

You have a couple of issues here the_content() echos the content to screen. You should be using get_the_content() which returns the content. Just remember, get_the_content() is unfiltered, so if you need filtered content, use apply_filters( ‘the_content’, get_the_content() ) which will return filtered content. Your explode() function is probably wrong as well. You are using a … Read more

empty query breaks other queries

Before we start, you should properly indent your code and remove php spam. This makes your code much easier to read and understand. Secondly, rather use curlies ({}) instead of syntax like :, endif and endwhile. It is easier to debug and to read. Just another tip, comment your code for future reference, it makes … Read more

Custom Query – Based on user input

While this is primarily a SQL question, there are WordPress components and Core has no efficient mechanism to pull this data that I am aware of. This has long been a problem in Core in my opinion. So: global $wpdb; // group name key $meta_key = ‘_create_new_group’; if (!empty($_REQUEST[‘q’])) { // user input $search = … Read more

Post with certain term and without any term

This should be possible with the tax_query parameters for WP_Query. The query is either for posts where any term NOT EXISTS, OR, for any posts where the term IDs are IN the provided array. ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘group’, ‘operator’ => ‘NOT EXISTS’, ), array( ‘taxonomy’ => ‘group’, ‘field’ => … Read more

sort query results by newest

WP_Query(array(‘post_type’=>’portfolio_item’, ‘post_status’=>’publish’, ‘posts_per_page’=>-5, ‘order’ => ‘ASC’)); See: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters for order parameters. Hope that helps.

get csv of users with user_meta

SELECT u.ID, u.user_email, u.display_name, um1.meta_value AS first_name, um2.meta_value AS last_name, um3.meta_value AS phone_number, um4.meta_value AS salutation, um5.meta_value AS title FROM wp_users u LEFT JOIN wp_usermeta um1 ON u.ID = um1.user_id AND um1.meta_key = ‘first_name’ LEFT JOIN wp_usermeta um2 ON u.ID = um2.user_id AND um2.meta_key = ‘last_name’ LEFT JOIN wp_usermeta um3 ON u.ID = um3.user_id AND … Read more

wpdb COALESCE won’t work

From what I could see, the query did return a result, but the COALESCE() result was not named, hence MySQL and WordPress use the entire COALESCE() query as the field name. To avoid that, you would use an alias for the COALESCE(), e.g. //$query = “SELECT COALESCE( <your queries> ) AS <alias>”; $query = “SELECT … Read more

Why my query ‘REPLACE INTO…’ does not work?

The reason is due to this code inside dbDelta() : // Create a tablename index for an array ($cqueries) of queries. foreach ( $queries as $qry ) { if ( preg_match( ‘|CREATE TABLE ([^ ]*)|’, $qry, $matches ) ) { $cqueries[ trim( $matches[1], ‘`’ ) ] = $qry; $for_update[ $matches[1] ] = ‘Created table ‘ … Read more

How to get events using multiple custom meta fields?

You can use your current code to create the query and then in your loop run a check before displaying the events something like <?php query_posts(‘meta_key’ => ‘end_date_value’, ‘meta_compare’ => ‘>’, ‘meta_value’ => $todaysDate); while ( have_posts() ) : the_post(); $post_custom = get_post_custom($post_id); if ($startDate < $post_custom[‘start_date_value’]){ //your loop here } } ?> keep in … Read more

Use mysql_query instead of $wpdb query

Simple and short: mysql_query() = Faster! $wpdb->get_results() = Safer! But in most cases since $wpdb is a global object and already in the memory using it will be be as fast as mysql_query(). Will this affect my performance? It can affect for better performance changes but they would be minor changes that its just not … Read more

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