Regenerate Slugs From Title of Posts

Yes, it is possible. Sample code, has to be tested and refined: // get all posts $posts = get_posts( array ( ‘numberposts’ => -1 ) ); foreach ( $posts as $post ) { // check the slug and run an update if necessary $new_slug = sanitize_title( $post->post_title ); if ( $post->post_name != $new_slug ) { … Read more

setup_postdata() does not seem to be working?

I could be wrong, but from what I’m seeing, “setup_postdata()” should be used when doing a custom select query (not just query_posts): http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query As well, if you want to use tags like “the_title()” and “the_permalink()” with that custom select query … you’ll need to use the variable name $post specifically (not another variable name) in … Read more

Query for custom post type? [closed]

query_posts( array( ‘post_type’ => array(‘post’, ‘portfolio’) ) ); which shows both normal posts and posts inside portfolio type or query_posts(‘post_type=portfolio’); for only portfolio. Use as normal WP Query – read the Codex: http://codex.wordpress.org/Function_Reference/query_posts#Usage and http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters <?php query_posts(array( ‘post_type’ => ‘portfolio’, ‘showposts’ => 10 ) ); ?> <?php while (have_posts()) : the_post(); ?> <h2><a href=”https://wordpress.stackexchange.com/questions/6417/<?php the_permalink() … Read more

What does setup_postdata ($post ) do?

Template tag functions rely on global variables to access the post being processed and retrieve data from it or related to it. The main variable among these is $post, which holds the post object itself. In your example it’s not explicit, but what is happening is that your loop assigns data to $post. If its … Read more

get_posts assigned to a specific custom taxonomy term, and not the term’s children

In looking at the WP_Tax_Query class in /wp-includes/taxonomy.php, I found that there is a ‘include_children’ option which defaults to true. I modified my original get_posts() call with the following, and it works great: $pages = get_posts(array( ‘post_type’ => ‘page’, ‘numberposts’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomy-name’, ‘field’ => ‘term_id’, ‘terms’ => 1, … Read more

How do I get posts by multiple post ID’s?

You can use get_posts() as it takes the same arguments as WP_Query. To pass it the IDs, use ‘post__in’ => array(43,23,65) (only takes arrays). Something like: $args = array( ‘post__in’ => array(43,23,65) ); $posts = get_posts($args); foreach ($posts as $p) : //post! endforeach; I’d also set the post_type and posts_per_page just for good measure.

Get Posts Under Custom Taxonomy

Your tax query is incorrect, field should be the field you want to query on: term_id, name, or slug – $posts_array = get_posts( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘fabric_building’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘fabric_building_types’, ‘field’ => ‘term_id’, ‘terms’ => $cat->term_id, ) ) ) );

When to use WP_query(), query_posts() and pre_get_posts

You are right to say: Never use query_posts anymore pre_get_posts pre_get_posts is a filter, for altering any query. It is most often used to alter only the ‘main query’: add_action(‘pre_get_posts’,’wpse50761_alter_query’); function wpse50761_alter_query($query){ if( $query->is_main_query() ){ //Do something to main query } } (I would also check that is_admin() returns false – though this may be … Read more

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