Tag Info

New answers tagged

1

I looks like you are using the custom meta boxes and fields github repo, which is an awesome library. I think the primary thing you need to do is a new WP_Query. Below is an example of that in action. The only difference is that in my example I made the "Assign to Homepage" a checkbox on the custom post type. <?php $args = array( 'post_type' => ...


3

Welcome the the WordPress Stack Exchange and congrats on your first post! First off, you may not want to use query_posts() here. Second off - the_post() needs to be before the_title() as it sets up all the posts functions such as the_title(), the_permalink() etc. and queues the next post in your while loop. Your Loop should look like this: <?php ...


-1

Take the_post(); out of your loop. I've never seen that actually used in a theme.


1

You have two issues here. The use of $image->ID in this line wp_get_attachment_image($image->ID, 'video-thumb'); This will give you the following error: NOTICE Error: [8] Undefined variable: image In all honesty, I think that should actually be $post->ID get_permalink() returns the permalink to the current post, which in this case ...


-1

You Can Display you custom post type using this method your pagination can work !!! <?php query_posts( array( 'post_type' => 'post', 'posts_per_page' => '2', 'paged' => get_query_var( 'paged' ) ) ); if (have_posts() ) : while (have_posts() ) : the_post(); ?> <!-- Start your post. Below an example: --> <div ...


1

On the advise of Robert and Pieter I rewrote the loops using WP_Query instead of query_posts. It works now. Thanks guys. Here's the code: <ul class="tabs"> <li class="tab-link current" data-tab="tab-1">Most Popular</li> <li class="tab-link" data-tab="tab-2">Recent</li> ...


2

The custom properties you refer to are dates which a stored in a custom table, and which are joined onto the query for events. At this point in time, when querying events, this table is only joined when only the 'event' post type is being queried. That is, you can search for events - but the dates are only pulled in if you are searching only for events. ...


1

is_page() relies on a complete global $wp_query object. If you call it before the action template_redirect has been fired, it might be impossible to get that data. Wait for a proper action. Example: add_filter( 'template_include', function( $template ) { if ( is_page( 27 ) ) echo 'this is the apply page'; return $template; }); You can ...


0

I believe you are talking about when the archive.php is used as a taxonomy page. If so, you will first need to check if the current page being viewed is actually a taxonomy page. If you don't do this check, you will get errors on pages that are not taxonomy pages, for instance date archive and category archive pages if they all make use of the archive.php ...


0

hey by using get_taxonomies( $args, $output, $operator ) Get a list of registered taxonomy Example- $args=array( 'name' => 'genre' ); $output = 'objects'; // or names $taxonomies = get_taxonomies($args,$output); if ($taxonomies) { foreach ($taxonomies as $taxonomy ) { echo '<p>' . $taxonomy->name . '</p>'; } } Source- ...


0

Maybe you could try this, though I'm not sure if it will work on archvie.php: echo get_query_var( 'taxonomy', 'Not Found' ); A complete list of Query Vars can be found here.


0

You cannot natively query broadly by taxonomy, only by terms If you study through Taxonomy Parameters in Codex it is now pretty easy to construct conditions for multiple sets of terms required. Still it's not completely flexible, I won't know easy way to do things like “having any term in some taxonomy” on top of my head.


0

Try to this: Add This custom_pagination() function to your function.php file function custom_pagination($numpages = '', $pagerange = '', $paged='') { if (empty($pagerange)) { $pagerange = 2; } global $paged; if (empty($paged)) { $paged = 1; } if ($numpages == '') { global $wp_query; $numpages = $wp_query->max_num_pages; ...


6

I've never seen it done before but the logic of the PHP IF/ELSE should mean you could simply plug a new query in after the ELSE: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part ( 'templates/post', 'main' ); endwhile; else: $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( ...


1

In your functions.php you can create a function that will hook into the pre_get_posts hook. Something like (just an example): function alter_query($query){ $query->set('post_parent', 0); } add_action( 'pre_get_posts', 'alter_query' ); There you can alter the main query. That way while(have_posts()) : the_post(); will still just normally work. (You ...


0

Your problem is definitly your custom query. There are a problem or two with your custom query which I will not handle now. You should work through this page (WP_Query) on how to properly construct a custom query Your real issue here is, and the question you must ask youself, is the custom query necessary? And the straight answer should be a solid NO. ...


-1

Is your loop running on the homepage? Add this to your functions.php and test. <?php function custom_loop_query( $query ) { if( ! is_admin() && $query->is_main_query() ) { $query->set( 'post_type', array( 'rock' ) ); } } add_action( 'pre_get_posts', 'custom_loop_query' ); ?>


-1

What if you save each query in a variable ? <ul> <?php $query1 = query_posts( array( 'posts_per_page' => -1, 'post_type' => array('specialties') )); if($query1->have_posts()): while($query1->have_posts()): $query1->the_post(); ?> <li> <!-- title from post type specialties --> ...


1

Try calling the nav before you reset the query. ... if (function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $my_query)); wp_reset_query(); // Restore global post data stomped by the_post(). ?>


0

The issue I had with my search was that the select field's name was the same name as the taxonomy being queried. When I used a different name for the select field my query worked as it should. <?php wp_dropdown_categories(array( 'name' => 'special_day_select', //anything else besides an existing taxonomy name. 'taxonomy' => 'special_day' ...


0

Please use the following code: $arg = array ( 'posts_per_page' => get_option('posts_per_page'), 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ); $wp_query = new WP_Query($arg); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); // do something endwhile; ...


-3

I found a WP Pugin than do all magic: WP - SNAP


2

You can make use of the build in loop counter, $current_post which you can access in the main query with $wp_query->current_post. (Just a note, the counter starts at 0, so post 1 will be 0) The main query uses WP_Query, $wp_query being the query variable used, so have a look at the Methods and Properties which you can make use of and the uses of these ...


0

Finally I got the code. Using below code, you can pick your OnSale products that are either Simple Product On Sale or Variable Product On Sale. Keep in mind that this code will pick every post in which you added sale price in the below image mentioned column . So avoid adding the price in this column (Shown in attached Image) if your sale price is same as ...


0

I ended up doing this - works perfectly. <?php $argsb = array('posts_per_page' => -1, 'post_status' => 'publish');?> <?php $blog = new WP_Query($argsb); if ( $blog->have_posts() ): ?> <section class="blog-slider slider"> <div class="flexslider"> <ul class="slides"> <?php while ( $blog->have_posts() ) : ...


7

You are thinking of WordPress templates as PHP application code. Essentially they are not that. WordPress templates by design are templates using Template Tags API. It is extra level of abstraction, that just happens to allow to use rest of PHP language too. The ease of template tags serves the popularity of WordPress and extremely low entry bar for people ...


1

WordPress data is all centered around the concept of "The Post" which is really little more that a colloquialism used to describe a complex array of data stored in the database. The pieces of data in that array make sense together in context. So technically, sure, you could extract all that data from that array with a foreach if you really wanted to. But ...


2

The loop is just an abstraction of the process of iterating over the posts returned by a query. As with all abstractions you pay some performance price for not using directly the language constructs like arrays, but it creates a more readable code (hopefully) as $q->hove_posts() is easier to grasp then ($I++ < count($q->$posts)). The main reason of ...


1

Every query object contains an array of the returned posts, so technically you could use foreach to display the posts, but I don't think it would simplify anything. First of all, you'll lose the loop start and end actions, and the ability to know if code is being executed within the loop or not, but the major thing you'll lose is the current post context - ...


0

I also was wondering how to incorporate anchors into my wp_query loop. The above code by Seamus was excellent, however I had to take out the # for the <div id="#post-<?php the_ID(); ?>"> line for it to work properly.


0

Here is the code I'm using: <?php global $custom_mb; // instead of using helper functions, you can also use ... $sch = get_post_meta(get_the_ID(), $custom_mb->get_the_id(), TRUE); foreach ($sch['docs'] as $img) { echo $img['imgurl']; } ?> Almost worked fine.


0

You need a loop within a loop - loop through a counter, and for each value, check for the existence of each key with the current counter value appended. // max custom field index $number = 40; // the counter $counter = ''; // the meta keys to check for $keys = array( 'custom_text', 'custom_image', 'custom_video' ); // all our custom field values ...


1

Use the page number to calculate a new date to get the week to fetch: $page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $date_to_fetch = time() - ( 604800 * ( $page - 1 ) ) ); $query_string = array( 'post_type' => 'post', 'date_query' => array( array( 'year' => date( 'o', $date_to_fetch ), ...


0

Instead of that try using; <?php get_userdata( $userid ); ?> For example; <?php $user_info = get_userdata(1); // get info for user id '1' $username = $user_info->user_login; $first_name = $user_info->first_name; $last_name = $user_info->last_name; ?> For more details visit this link.


0

What do you mean by "dynamic" ? Do you want it to work with different posts? If so, that's simple. Before your get_posts query function, get page terms, and pass them to your array. You can get taxonomies with <?php get_the_terms( $yourpostid, 'your_custom_taxonomy'); ?>


-2

Go to "Pages" and find the page with the ID. Open it in editor. On the right hand side, look for "page attributes". You can add php files here. All you have to do is, create a PHP page under your theme, and add this to your beginning of the file: <?php /* Template Name: A PAGE NAME HERE */ Reload, and your file shows up with the A PAGE NAME HERE ...


0

You're just echoing the values. If you're wanting to actually create an array with the data in it I think you'll need something more like this. $args = array( 'post_type' => 'locations', 'posts_per_page' => 10 ); $loop = new WP_Query( $args ); $addresses = array(); while ( $loop->have_posts() ) : $loop->the_post(); $zipcode = ...


0

Alright I figured it out! $args = array( 'post_type' => 'vendors', 'order' => 'asc', 'orderby' => 'title', ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { echo '<ul>'; while ( $query->have_posts() ) { $query->the_post(); $category = get_the_category(); echo '<li class="'; echo ...


0

After giving it another look with some fresh eyes, I decided to add a third loop within Loop 2 and not have it working as desired: $media_args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'products', 'field' => 'term_id', ...


0

OK I got it. First of all, add a counter before The Loop. $my_posts = 0; Then in The Loop increment it by one each time. $my_posts++; Stickies are always at the very top, so compare the number of all sticky posts with current post in The Loop and display custom message. if( $my_posts === count( get_option( 'sticky_posts' ) ) ) echo 'this will only ...



Top 50 recent answers are included