get post id using the $query_vars variable

When viewing a single post, get_the_ID(); used within the loop will return the current post’s ID. But I don’t have a reference page that has the list of $query_vars params… Dumping it global $wp_query; var_dump($wp_query->query_vars); would provide such a reference. Where you’d subsequently see that $wp_query->query_vars[‘page_id’] yields the page ID.

add spans and characters into paginate_links

The function paginate_links() can return “plain”, “list” and “array” (http://codex.wordpress.org/Function_Reference/paginate_links). Just define the type as array then you’ll be to display it as you want: <?php global $wp_query; $big = 999999999; // need an unlikely integer $paginate_links = paginate_links( array( ‘base’ => str_replace( $big, ‘%#%’, get_pagenum_link( $big ) ), ‘format’ => ‘?paged=%#%’, ‘current’ => max( … Read more

Retrieve or Query Pages by ID

This is an inappropriate use of query_posts() which is only for modifying the main query for the page. Additionally, even if you change your snippet to use get_posts(), your template tags (e.g. the_excerpt()) won’t work as get_posts() isn’t a method of looping through posts, it just returns an array of posts. What you want is … Read more

How to Loop within a Loop (Display Children and then Grandchildren)

Try something like: <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div class=”parent-post”> <?php the_title(‘<h2>’, ‘</h2>’); ?> <?php $children = new WP_Query( array(‘post_type’ => ‘page’, ‘post_parent’ => get_the_ID() )); ?> <?php if ( $children->have_posts() ) : ?> <ul class=”post-children”> <?php while ( $children->have_posts() ) : $children->the_post(); ?> <li><?php … Read more

List the 5 most recent child pages

Assuming you know (or know how to get) the $id (as an integer) of the parent post, use the post_parent parameter: $albums = new WP_Query(array( ‘post_type’ => ‘gallery’, ‘posts_per_page’ => 6, ‘post_parent’ => $id )); Edit Based on this comment: I don’t know the parent post. I want to list the most recent child pages … Read more

The use of including upgrade.php when building custom queries

No, and in fact you should not include the wp-admin/includes/upgrade.php file in a plugin. There is no real valid use case for doing so. It doesn’t do anything for you or add any useful functions for a plugin. As for your question, you say “it doesn’t work” but you fail to define what that means. … Read more

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