Tag Info

New answers tagged

1

Can someone please explain how "$posts" is used within the loop? It isn't. It returns the array of queried posts , but it is insignificant and not used at all: if you remove it than the code works the same: global $query_string; query_posts($query_string.'&cat=-9'); if (have_posts()) : while (have_posts()) : the_post(); ... endwhile; endif; ...


1

You can do this in one loop without as custom query. A couple of clever functions should get you there So lets look at a solution. First things first. I would suggest to separate your code completely here for easiness of reading and organisation. Roll back the changes in content.php and use this template only for all other templates. Create a separate ...


0

Ok, I've had a major breakthrough with the multiple loops on the smaller thumbnails and managed to find an answer to question 1. I now just need help with the answer to question 2! Here is the updated code for the thumbnail rows within one loop: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' ...


1

You can filter any WP query using pre_get_posts(). The (sometimes) tricky part is that it is run against all queries of WP so you need to pinpoint your query using WP conditionals (is_admin(), is_page(), is_archive(), etc... ). You'll find a few useful examples on that page, too.


0

Yes, I think the only way is to remake the loop, the slightly tricky bit being to make the $args array the same as get_posts()'s defaults: $args = array( 'post_type' => 'event', 'posts_per_page' => 6, 'post_status' => 'publish', // If post_type 'attachment' then 'post_status' => 'inherit' 'orderby' => 'date', 'order' => 'DESC', ...


-3

**The default syntax for showposts is-** <?php $query = new WP_Query (array( 'showposts' => 5, ) ); while ($query->have_posts()): $query->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> ...


0

Sounds like you're looking for the NOT IN value of the operator argument of a tax_query. Depending on your situation, you should use either WP_Query or pre_get_posts. Your tax_query would then look something like this: 'tax_query' => array( array( 'taxonomy' => '{your taxonomy slug}', 'field' => 'slug', 'terms' => ...


0

For testing purposes in your functions.php file, try this - add_action('init', 'my_test_get_all_bands', 99); function my_test_get_all_bands(){ echo '<pre>'; print_r(get_all_bands()); echo '<pre>'; } As I was attempting to say in my comment to your question (and as Pieter Goosen explained rather better), if your taxonomies have not yet been ...


0

What you can do is the following: http://codex.wordpress.org/Function_Reference/get_posts_by_author_sql <?php $where = get_posts_by_author_sql( 'post', true, $user->ID); // get post query global $wpdb; $query = "SELECT ID FROM $wpdb->posts $where"; $post_ids = $wpdb->get_var( $wpdb->prepare( $query, 'Get all posts' ) ); ?> Did not try ...


2

The issue is that you are using the function query_posts this only queries the default result on that page. It's advised that you use wp_query instead, it just eliminates the margin for error or unexpected results. You can create a new query like below, and specify explicitly how many posts to return: <?php $sticky = get_option( 'sticky_posts' ); ...


1

You can make use of get_post to get the post objects of a given post. This will be unfiltered objects, so you would want to make use of apply_filters and the appropriate filters described in the linked page. If you need to get info from a custom field, whether native custom fields of ACF fields, you can simply add the ID to the get_post_meta for native ...


0

I guess you have 4 different news, you want display first news use large image of each page and the news of large image is different others, right? If you right, the following code, maybe work for you. <?php $b=1; $args = array( 'tax_query' => array( array( 'taxonomy' => 'gens', 'field' => 'slug', ...


0

I don't know why have you put $b%4==1 condition. You can simply check for $b==1.And one more thing I would suggest is to use if and else both.So code would be something like this: <?php $b=1; $args = array( 'tax_query' => array( array( 'taxonomy' => 'gens', 'field' => 'slug', ...


0

I found the issue: it is a strange server configuration. The port mapping is a bit odd, since the port 80 is mapped to a five-digit port on the other side. That's why WordPress redirected into a loop. To fix this kind of issue enter the HTTP port number into your WordPress settings: http://your-domain.com:80/directory or ...


0

As mentioned in my comment, ensure you test the following in a "clean" browser: Set siteurl & home to http://www.example.com/wordpress-subdirectory Set permalink_structure to nothing Set active_plugins to nothing Ensure there are no WP_SITEURL or WP_HOME constants defined in your wp-config.php Remove all rewrite rules to do with WordPress from your ...


0

Did you try: function exclude_category($query) { if ( is_page('slug-of-page') && isset($query) ) { $query->set('cat', '-3'); } return $query; } add_filter('pre_get_posts', 'exclude_category');


1

First off, I'd like to note a few things wrong with your Post Type and Taxonomy set up. There's a few settings in your $labels that don't make sense: $labels = array( ... 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_mime_type' => 'image', ); These last 4 options ...


0

Your's css is messed up becouse you have invalid html code. I'v counted 9 opening <div> tags and only 8 ( 7 in seccond code block ) closing tags Fix the html and your css will work just fine. About the_content() in your example it should work just fine, check if you have content added to post. When you'r using the_excerpt() check if your excerpt ...


1

your callback function must be like this: function cienna_show_slider_callback() { global $post, $product, $woocommerce; // just in case if your template file need this ob_start(); ?> <?php woocommerce_get_template( 'archive-product.php'); ?> <?php $output = ob_get_contents(); ob_end_clean(); echo $output; die(); }


1

I wrote an article on this a while back: Excluding Certain Posts Or Pages From Search Results In WordPress But the long and short of it is: function mySearchFilter($query) { if ($query->is_search) { $query->set('post_type', 'post'); }; return $query; }; add_filter('pre_get_posts','mySearchFilter'); You can add that to your ...


0

You can access the current post ID within the loop via get_the_ID() while ( $secondary_loop->have_posts() ) : $secondary_loop->the_post(); rating( get_the_ID() ); endwhile; wp_reset_postdata();


3

The 'the_posts' filter hook allows you to edit posts that are going to be displayed in a loop. It's fired for all queries (the main and the secondaries) so you need to check that the query you're acting on is the right one. That said in your case you can: send a query variable to individuate the selected post use 'the_posts' filter to move selected post ...


4

Found the answer from the WordPress docs. For what the query is ordered by, I use: global $wp_query; echo $wp_query->get('orderby'); For the order by which the posts are queried: global $wp_query; echo $wp_query->get('order');


0

The problem seems to be in the Loop. Inside the Loop you are not incrementing the $the_query. You may change the code for the Loop as below: // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); // Add this line to fix the issue smr_product_the_frontend_item(); } } else { ...


0

'p' => $id why you this? and if you create show all pages on your testimonial or slider show whatever is_page(); use condition on footer, header, index and YOUR-TEMPLATES


0

I am sure there's an easier way to accomplish this, but this how I would've done. Query all posts with category X and status X Update query results with status Y. $target_category = 'news'; $change_status_from = 'draft'; $change_status_to = 'publish'; $update_query = new WP_Query(array('post_status'=>$change_status_from, ...


0

<div class="pr_grid_cell clearfix"> <?php //for each category, show posts $categories=get_categories(); foreach($categories as $cat) { $args=array( 'post_type' => 'products', 'showposts' => -1, 'category__in' => array($cat->term_id) ); $posts = new wp_query($args); // This is the best way to if ($posts->have_posts()) while ...


0

With the help of a friend, i got the solution: <?php $line = 1; $col = 1; while(have_posts()) : the_post(); if ($line % 2 == 0) { $class = 'grid_2'; // class for the 3 smaller posts } else { $class = 'grid_3'; // class for the 2 bigger posts } ?> <div ...


1

Yes you can do that using $wp_query->current_post inside the loop. It returns the current posts index number inside the loop (starting form 0). Have a look at the following code block <?php global $wp_query; while(have_posts()){ the_post(); the_title(); //do your other stuff if($wp_query->current_post==1){ //do what you want ...


1

You will have to run a custom query for that. Here is the query for displaying posts from a particular year. I have used year 2012 as an example. $args = array( 'post_type' => 'post', 'ignore_sticky_posts' => 1, 'year' => '2012', ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( ...


1

Wordpress saves page templates that is assigned to a specific page in the db in the wp_postmeta table. These are saved as follows: 'meta_key' => '_wp_page_template', 'meta_value' => 'NAME_ OF_TEMPLATE' With this in mind, you can loop through pages which shares a specific page template, using get_pages (You can also make use of WP_Query) Example: ...


0

Use get_template_part, for example if your template is named sale.php you can use: get_template_part( 'sale' ); http://codex.wordpress.org/Function_Reference/get_template_part


0

Near the top of your code, you have wp_reset_postdata();. As explained in the Functional Reference it alter the main loop and should be avoided. Looks like that's what's causing your issue.


7

Of course, there's an API function - hidden in the depth of core - to retrieve the parts before and after the <!--more--> tag in the content. Due to exactly zero naming conventions, the handy parts in WP are often overseen: get_extended(). // In the loop, after `the_post()` filled the global `$post`: $info = get_extended( $post ); // The resulting ...


3

EDIT OK, there is a very hidden native function, get_extended() that I never knew about and greatly explained by @kaiser in his answer. My answer should only be an extension to the answer by @kaiser ORIGINAL ANSWER There is no native function to do this. The best here would be to use a PHP function like strpos to search for the more tag, and then do ...



Top 50 recent answers are included