Get posts under a category with SQL

SELECT p.ID AS postId, p.post_name, p.post_title, p.post_content, p.post_excerpt, p.post_status, p.post_type, p.post_author, p.guid, p.post_modified_gmt, (SELECT group_concat(t.name SEPARATOR ‘, ‘) FROM wp_terms t LEFT JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id LEFT JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = ‘category’ AND p.ID = tr.object_id ) AS category FROM `wp_posts` AS p LEFT JOIN `wp_term_relationships` … Read more

Get posts from specific taxonomy term

this code will display the post from all taxonomy in wordpress: $args = array( ‘type’ => ‘post’, ‘child_of’ => 0, ‘parent’ => ”, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => 1, ‘hierarchical’ => 1, ‘exclude’ => ”, ‘include’ => ”, ‘number’ => ”, ‘taxonomy’ => ‘season’, ‘pad_counts’ => false ); $taxonomy = get_categories( $args … Read more

get_terms – name__like a number

Looking at the get_terms function definition, the value for name__like will be passed to the SQL query like: ” AND t.name LIKE ‘{$name__like}%'” As such, I believe that you can only search for one of the numbers. As an alternative strategy, you could iterate over the numbers you want to pull from the database: $terms … Read more

Query posts from a child taxonomy term id

i solved the problem if(isset($_POST[‘main_brand_id’])) { $term_id .= $_POST[‘main_brand_id’]; $term = get_term( $term_id, ‘state’ ); $slug = $term->slug; global $post; $post_id = $post->ID; $args = array( ‘post_type’ =>’dealers’,’taxonomy’=>’state’, ‘term’ => $slug ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); echo ‘<option value=”‘.$post->ID.'”>’ $options .= the_title(); echo ‘</option>’; endforeach; die(); } … Read more

List related terms + taxonomies

You probaby want get_terms(). WordPress keeps a count of the number of posts that use a taxonomy and you can filter your query using it: // get all the terms in the ‘category’ taxonomy $terms = get_terms(‘knife’); // list all the terms that have at least one post foreach ($terms as $term) { echo “{$term->name} … Read more