INSERTING Data into table with placeholders

I found the answer, in the codex. I just used it’s code and adapted it, this code: $wpdb->query( $wpdb->prepare( ” INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s ) “, 10, $metakey, $metavalue ) ); So it works now.

Showing HTML if Post is In Certain Taxonomy Term

Try using has_term(). Something like this: <?php if( has_term(‘term1’, ‘taxonomy_name’, $post) ) { ?> <img src=”http://www.site.com/wp-content/themes/site/img/stars-01.png” width=”100″ height=”21″ alt=”default”> <?php }elseif ( has_term( ‘term2’, ‘taxonomy_name’, $post) ) { ?> <img src=”http://www.site.com/wp-content/themes/site/img/stars-01.png” width=”100″ height=”21″ alt=”default”> <?php } else { ?> <img src=”http://www.site.com/wp-content/themes/site/img/stars-01.png” width=”100″ height=”21″ alt=”default”> <?php } ?> You may also want to try using shorthand … Read more

If product is in sub-category show code

You can probably just make use of has_term( $term, $taxonomy, $post ) which will check if the specific post belongs to the term given You can do something like this (Edit: Add post ID if this is used in a function) global $post; if(has_term( ‘lucha’, ‘product_cat’, $post->ID )) { //do something if post has lucha term }else{ //do something … Read more

Accessing Post ID Within Loop

The problem probably comes from whenever a $post has no terms set. You need to set $brand = array() outside your IF statement, add it just under get_the_terms(). At that point it also wouldn’t hurt to wrap your switch statement in a if( ! empty( $brand ) ) { Another problem I see with this … Read more

Get current post’s nav menu name (term name)

You are missing a link. The posts are not assigned to the menus directly. There is a post type nav_menu_item in nav_menu taxonomy which links posts (or other kinds of destinations) to their place in menu. This snippet should get you started on retrieval: $menu_items = get_posts( [ ‘post_type’ => ‘nav_menu_item’, ‘meta_query’ => [ [ … Read more

How to query if meta_key does exist or not?

Adding a NOT EXISTS clause should force LEFT JOINs: ‘meta_query’ => array( ‘relation’ => ‘OR’, array(‘key’ => ‘file_gallery’, ‘value’ => ‘1’, ‘compare’ => ‘!=’), array(‘key’ => ‘file_gallery’, ‘compare’ => ‘NOT EXISTS’), ),

How can I get 3 different taxonomy type terms in a div class element?

If using get_the_terms, you can just do your if loop once for each taxonomy and then join them after the three loops. Of course, it would probably be more efficient to use: wp_get_post_terms( $post_id, $taxonomy, $args ); You could then do something like: wp_get_post_terms( $post_id, array( ‘resource_roles’, ‘resource_media’, ‘resource_theme’ ) ); Which would pull all … Read more

Double slash in the_terms URL

First Assumption: That an extra slash was being added for some reason To see what was going on, I wanted to see what was going on in the array. When I print_r() the array I get the following: Array ( [10] => stdClass Object ( [term_id] => 10 [name] => Mozilla [slug] => mozilla [term_group] … Read more