Find all posts via SQL beginning with A of type B

Try this.. SELECT * FROM $wpdb->posts p INNER JOIN $wpdb->term_relationships tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id=tt.term_taxonomy_id inner join $wpdb->terms t on t.term_id=tt.term_id and t.slug=’igralni’ WHERE p.post_title LIKE ‘А%’ AND p.post_type=”filmi-i-serialii” AND p.post_status=”publish”

Remove last comma from this query

Looks like you’re trying to build up some JSON. Why not use what PHP already provides, which has the advantage of escaping characters too? global $post; $data = array(); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); $thumb=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’); $thumb2=wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’); $url = rwmb_meta( ‘smb_katalozi’ ); $data[] = array ( ‘image’ => … Read more

Exclude sticky posts from query

You should also use ignore_sticky_posts=1 (it’s default value is 0, so sticky posts aren’t ignored and returned at top of posts list). More on pagination parameters: http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

Set posts per page for parent category and it’s all children

You want get_term_children. function hbg_category_query( $query ) { if( $query->is_main_query() && $query->is_category()) { $categories = get_term_children(1,’category’); $categories[] = 1; // add your special category if (is_category($categories)) { $query->set( ‘posts_per_page’, 32 ); } } return $query; } add_action(‘pre_get_posts’,’hbg_category_query’); Barely tested, but I think that will work.

Cannot retrieve home url with custom queries

home_url() uses get_home_url() which in turn uses get_option( ‘home’ ) to retrieve the home url. The code in get_option() includes this: // If home is not set use siteurl. if ( ‘home’ == $option && ” == $value ) return get_option( ‘siteurl’ ); I didn’t unwind all the previous code in the function, but it … Read more

Custom Query problem access the values

You’ve asked for an array and you are trying to use an object. $key = “sc_event_year”; $value = $today_year; global $wpdb; $results = $wpdb->get_results(“SELECT * FROM $wpdb->postmeta WHERE meta_key = ‘sc_event_year’ AND meta_value = $value”, ARRAY_A); foreach ($results as $result){ echo $post_id = $result[‘post_id’]; // <– here was the problem } Unless $value is a … Read more

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