Hot answers tagged

5

You need to specify a post type in your WP_Query arguments when you need to query any other post type accept the build in post type post. By default, post_type is set to post, so when no specific post type is set manually by the user, WP_Query will query posts from the post type post Additionally, caller_get_posts have been deprecated for a very very long ...


4

That's because the main query is being discarded and replaced with your custom query. You've not told your custom query to look for that tag, so why would it? You might also notice your pagination is broken for the same reason, you've not told the new query which page you're on, so why would it pull the right page? What's more, that main query is expensive! ...


3

"best" greatly depends on context. guid is probably (with some debate about it) the best way to uniquely identify a post, but not all import/export plugins leave it alone without changes. ID is a good identifier if you do not care about import and export. Slug is problematic because they might be changed by the user. The best thing to do if you need to ...


2

Basically, when you add a new term, WordPress will use term_exists() to validate term before add it to database. term_exists() uses sanitize_title() which uses remove_accents() and sanitize_title_with_dashes() to sanitize term. remove_accents() will converts all accent characters to ASCII characters and sanitize_title_with_dashes() will limits the output ...


2

My first port of call is to call global $post; - as that sets you up to use $post->ID ... if you are using it then the next step is to display each part separately e.g. print_r($tags); echo $first_tag; see what's displayed in each part, this will help diagnose where the issue is, as without seeing your code working, we can't say why it's not working.


1

Give something like this a try: (it came from the same page you linked to, just scroll down a bit more). $args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', // searches for posts meeting both conditions array( 'taxonomy' => 'midgets', 'field' => 'slug', 'terms' => array( ...


1

It's outputting the word Array which is self explanatory. Instead of direct echoing it, you will need to turn the array into a string. Try implode, something like: Tags: <?php $my_theme = wp_get_theme(); echo implode(', ', $my_theme->get( 'Tags' ) ); ?>


1

After join term_id exist two times. You should specify which term_id you are querying by prefixing full table name (or alias). Also there is a other error term_taxonomy.term_id = terms.term_id missing table prefix. So the updated query will look like $query = 'SELECT term_taxonomy_id, ' . $wpdb->prefix . 'terms.term_id, taxonomy, name FROM ' . ...


1

Whithout knowing the value of $tags variable (you are not showing it to us), the only thing I see wrong in your code is the tag_in argumente, the correct one is tag__in (note the double _). Also, note that tag__in works with the core tag taxonomy. This taxonomy is not supported by custom post types by default, only by the standard post type.


1

Pieter's answer does work, but it displays all sticky posts even on pages when we want to display filtered posts (to a given category for instance). The following works for me. Adding this to functions.php only displays stickies within the subset of filtered posts : add_filter('the_posts', 'bump_sticky_posts_to_top'); function ...



Only top voted, non community-wiki answers of a minimum length are eligible