spliting posts into two columns

You could always try to create 2 arrays of titles, say $left and $right, $odd and $even, or $tom and $jerry, and fill them with the titles during your loop, and print them after the loop has ended like so: Create array $left = $right = array(); Then unleash your loop [edited the below to … Read more

Exclude posts with empty post_content in wp_query

This isn’t possible with a standard WP query, and you’ll have to leverage the use of posts_where before the WP_Query is called. function the_dramatist_filter_where($where=””){ $where .= ” AND trim(coalesce(post_content, ”)) <>””; return $where; } In the above, we’re simply only selecting posts where the column post_content isn’t empty. Then add the filter. add_filter(‘posts_where’, ‘the_dramatist_filter_where’); Now … Read more

List User order by ID in Descending order (Backend)

I first thought that pre_user_query would be that hook for the job. But I think using the equivalent of pre_get_posts, which is pre_get_users, would be suitable here. You also said you wanted to run this in admin. So we will check that before running this. function my_custom_order_users_by_id( $query ) { //Check that we are in … Read more

Loop posts only excluding first post

You don’t need separate queries, you can run multiple loops on the same query- // output first post if( have_posts() ){ the_post(); the_title(); } // output the rest of the posts… if( have_posts() ){ while( have_posts() ){ the_post(); the_title(); } } You can also use rewind_posts() to reset the current post back to 0, as … Read more

How to filter custom taxonomy categories on archive?

Recap: You created a custom post type = “downloads” and a custom taxonomy = “downloads_category” with a rewrite to “categoria-de-downloads” First: The “is_tax” at the head of your archive.php is failing because the name of your custom taxonomy should be “downloads_category“; it must be spelt with an underline rather than a hyphen (Codex). You also … Read more

Pass array of taxonomy terms to wp_query

The problem is ambiguity, you can’t just put in ‘relation’ => ‘OR’ in the main parameter list, because how would WP_Query know if it’s for the tax_query and not the meta_query? For how it’s supposed to work, and where the relation parameter goes we need to refer to the official docs for WP_Query which gives … Read more

$wpdb insert is not work

First insert the global. global $wpdb; Then You have to check your quotes properly. $sql = $wpdb->prepare( “INSERT INTO `$table_name` (`name`,`email`,`phone`,`message`,`rq`,`url`) values ($name, $email, $phone, $address, $msg, 1, $url)”); $wpdb->query($sql); OR $wpdb->insert(‘$table_name’, array( ‘name’ => $name, ’email’ => $email, ‘phone’ => $phone, // … and so on ));

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