Can’t create posts with WP DB Abstraction Plugin

Finally got it, my problem was in wp-include/post.php, due to bad translations of the queries from MySQL to SQL. I had to replace code in wp_insert_post function with this code: if ( empty($post_date_gmt) || ‘0000-00-00 00:00:00’ == $post_date_gmt ) { if ( !in_array( $post_status, array( ‘draft’, ‘pending’, ‘auto-draft’ ) ) ) $post_date_gmt = get_gmt_from_date($post_date); else … Read more

SQL – JOIN last child

This is the solution I came up with: SELECT child_ID, posts.post_author, wp1.post_author FROM wp_posts posts LEFT JOIN ( SELECT MAX(ID) as child_ID, post_parent FROM wp_posts WHERE post_type=”ticket_reply” GROUP BY post_parent ) sl ON posts.ID = sl.post_parent INNER JOIN wp_posts wp1 on sl.child_ID = wp1.ID WHERE posts.ID = 1499

How to display a specific category using a custom Query in WordPress?

Why are you using $wpdb to query from database. Use WP_Query or get_posts instead. This is how you can query from WordPress database and get 4 latest posts from category id 24. <?php $args = array( ‘post_type’ => ‘post’, ‘cat’ => 24, ‘posts_per_page’ => 4, ‘ignore_sticky_posts’ => 1 ); $my_query = new WP_Query( $args ); … Read more

Query to get data of a post, if in category?

Your query won’t work as it will simply ignore your taxonomy query. This is not a bug but expected behavior. When using p as your parameter, every other query parameter are ignored/bypassed like for example post_type, tax_query and any taxonomy related queries like category and tag parameters due to the fact that you are directly … Read more

Creating a “forum” – showing last post or last commented post

You can add the standard taxonomy joins to the query: global $wpdb; $cat_id = 79; // Whatever. $sql = ” select wp_posts.*, coalesce( ( select max(comment_date) from $wpdb->comments wpc where wpc.comment_post_id = wp_posts.id ), wp_posts.post_date ) as mcomment_date from $wpdb->posts wp_posts JOIN $wpdb->term_relationships AS tr ON wp_posts.ID = tr.object_id JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id … Read more

Help with SQL query, how to add taxonomie terms with value stored in options?

ok folks, i did it anothere way.. here’s how i did it: add_filter( ‘pre_get_posts’, function( $query ) { if( ! is_main_query() || ! is_post_type_archive() || ! $query->get( ‘section’, false ) ) return $query; global $wpdb; $section = $query->get( ‘section’ ); unset( $query->query[‘section’] ); unset( $query->query_vars[‘section’] ); $query->tax_query = false; $query->set( ‘tax_query’, false ); $cateroties = … Read more

Protect custom form from SQL injection

Yes, $wpdb->update is sufficient protection. You should not escape or prepare the data. From the documentation of wpdb: data (array) Data to update (in column => value pairs). Both $data columns and $data values should be “raw” (neither should be SQL escaped). This means that if you are using GET or POST data you may … Read more

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