Tag Info

New answers tagged

2

Use array_unique() <?php foreach($users as $user) { $states[] = get_cimyFieldValue($user->ID, 'STATE'); // Grabing their state from their profile page } $states = array_unique($states); ?> <div class="state"> <input type="hidden" name="search_type" value="members"> <select ...


0

It can be done by AJAX, Read this tutorial which with a little modification can do what you want.


1

There's no reason to use multiple loops to get this effect: The look you want comes from the jQuery Masonry script, which is included in recent versions of WordPress. Your post list as you describe it is just the standard post index, so use a single standard loop -- that is, a WordPress loop, as described in the Codex: http://codex.wordpress.org/The_Loop. ...


1

There is no term_id parameter. You need a tax_query. $args = array( 'post_type' => 'my_post', 'posts_per_page' => 6, 'tax_query' => array( array( 'taxonomy' => 'yourtaxname', 'field' => 'id', 'terms' => 1 ) ) ); $query = new WP_Query( $args ); Notice that I've use new ...


0

you can always do a new wp_query to get the latest post from given category and display its thumbnail etc.. Something like $new_query = new WP_Query( 'cat=your_category_id&showposts=1' ); if( $new_query->have_posts() ): while( $new_query->have_posts ): $new_query->the_post(); the_post_thumbnail(); endwhile; endif; wp_reset_query(); replace ...


0

have_posts() iterates over all posts found and actually returned in the query which depend in the posts_per_page parameter. And for your second question, using query_posts() does overwrite the query and its not really the recommend method to alter or modify the query result, here is a nice question that explains better ways : When should you use WP_Query ...


0

I found that I was able to do this by using the Instagrate Pro plugin, which creates individual posts for every image it pulls in from Instagram. The standard loop then just pulls in those posts into the archive.


2

When you initiate a Loop, split it up like so: <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- do stuff ... --> <?php endwhile; ?> <?php endif; ?> Anything inside the if statement but outside the while statement will run if have_posts is true, but will not be ...


0

to solve this you can create a page template, on this page template 1.get the top level categories only, set parent value to zero $args = array( 'orderby' => 'name', 'parent' => 0 ); $categories = get_categories( $args ); 2.get posts in all parent categories foreach ( $categories as $category ) { ...


1

If your slider shows posts in a particular category, which is defined by the variable $panel, then you can cleanly separate the slider posts from the normal flow. Display Slider Use new WP_Query() in your template to output the slider: $slider = new WP_Query( array( // 'showposts' is deprecated; use 'posts_per_page' 'posts_per_page' => 10, ...


2

Track the IDs, and "exclude" them with post__not_in. It is hard to tell exactly what does what with the disjointed way you posted your code but the general case solution is .. $c_posts = new WP_Query("showposts=10"); $tracker = array(); if ($c_posts->have_posts()) { while ($c_posts->have_posts()) { $c_posts->the_post(); $tracker[] = ...


0

In the WordPress admin Go to WooCommerce > Settings, click on the Pages tab. In the Shop Pages section make sure you have a setting for Pay Page: http://cld.wthms.co/AeDZ Make sure that page exists and has the shortcode [woocommerce_pay] in the content: http://cld.wthms.co/Y2h8


1

If the goal is such: I do not want to show the date/time on the front page to keep the layout cleaner, only on the other pages that this loop is displayed on. Then you should be able to use a simple conditional: <?php if ( ! is_front_page() ) { ?> <p><?php the_time('F Y'); ?></p> <?php } ?> Without knowing exactly ...


3

Before I address your main issue, I must point out a glaring syntax error: <?php if( !is_home() || !is_front_page() ) { ?> <p><?php the_time('F Y'); ?></p> <?php endif } ?> Why is the endif there? It makes no sense whatsoever, and everything in programming has a purpose/reason. You might as well change it to ...


5

Let's see if I can confuse myself. If either of your two OR conditions is true the code executes. is_home and is_front_page can return true for different pages, negated in your case. If you have a static from page, which it sounds like you do, then is_home is the blog index page. Note: WordPress 2.1 handles this function differently than prior ...


0

I believe you want get_queried_object. That will return information about the page per se and not necessarily about the posts/pages being displayed in the Loop. Be aware that it returns very different information depending on the type of page you are one. It will return user information on an author archive, for example, but category information on a ...


-1

Try is_single( $page_id ) instead. Basically is_post() has been deprecated. http://codex.wordpress.org/Function_Reference/is_single


0

in your code, you are checking the category of a post which is quite random outside of the loop and when the posts have more than one category; the category ID of a category archive page is usually: $cat_ID = get_query_var('cat');


0

$_post = get_queried_object(); $post_id = $_post->ID; It's somehow like that how single_post_title() gets the title.


0

Try using $wp_query global variable: global $wp_query; $postid = $wp_query->post->ID;


0

@userabuser's input provides a useful discussion on using Custom Post Types to solve the customisation need. However, this still left unanswered my main question: Can I interrogate a pages template type or custom meta data within a loop? I wanted to use wordpress static pages with a custom template as an alternative to Custom Post Types. For the small ...


2

Calling the_post() is what advances the internal current_post counter that have_posts() checks the value of within the loop. With this in mind, you can call the_post() once outside the loop and use any template tags you wish, then run the loop as normal and it will pick up and continue from the second post. the_post(); // this is the first post! ...


0

You just have to set a new query and play with the parameter offset see documentation 'offset' => 1 will exclude the most recent post for example.


3

To print just the total number of comments for a given post ID, use the count argument: echo get_comments( array ( // post ID 'post_id' => 149, // return just the total number 'count' => TRUE ) ); To get the total number of all comments of all posts on the current page, you can use the comment_count property ...


0

In case anyone runs into trouble like I did, I figured it out! $taxonomy_1 = get_terms( 'taxonomy_1', $args_1 ); $taxonomy_2 = get_terms( 'taxonomy_2', $args_2 ); foreach( $taxonomy_1 as $tax_1 ) { foreach( $taxonomy_2 as $tax_2 ) { $posts = get_posts( array( 'posts_per_page' => -1, ...


0

In the loop you should check for the post type, so something like: if (get_post_type() == "Your_Allowed_Post_Type"){ comments_template(); }else{ //No COMMENTS HERE , show what you want..or nothing :) }


1

In principle you should be able to achieve that by using categories for your posts. So while your normal loop for the single.php might look like this (I'll just leave the markup I had in there since I took this out of a file I had lying around. It may of course be different from yours.) <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ...


0

I didn't test this, but the WP Query page says: Pagination Note: Use get_query_var('page'); if you want your query to work in a Page template that you've set as your static front page. So, perhaps you need this: $page_number = get_query_var('page') ? get_query_var('page') : 1; [ ... ] $args = array( 'post_type' => $post_types, 'page' ...


2

You are overwriting the query that loads with the page (which you saved to $temp) - why not just use the one that loads with the page: while(have_posts()) : the_post(); // put the post here endwhile;


1

try yo use the build-in loop counter: <a data-slide-index="<?php echo $wp_query->current_post; ?>" href=""><?php echo $imagethum; ?></a>


2

I am not going to write your form for you, but create a form and submit it to a page to do the processing, or use the AJAX API. Then use WP_User_Query to actually search for users. It is a very WP_Query-like class that should let you do everything you want including search for user metadata from the $wpdb->usermeta table by passing a meta_query parameter ...


2

... for example inside my loop if i have added following argument 'post_per_page' =>-1 my loop is showing all posts but now i can't insert my custom number of posts inside admin panel if I enter "Blog pages show at most" 3 (three representing number of posts) they are ignored and loop is showing all posts. Of course you can't. You have ...


3

I'm not sure why your blank variable method should work, but it seems dodgy to me. I would explicitly set the posts_per_page to the number defined in settings: 'posts_per_page' => get_option( 'posts_per_page' )


0

$args = array( 'post_type' => 'product', 'numberposts' => -1, 'orderby' => 'meta_value_num', 'order' => get_query_var('order'), 'meta_key' => '_price' ); $lastposts = get_posts( $args );


1

Consider this snippet here to accomplish your task. If you add it to your functions.php file, the Open Graph tags will be populated automatically as part of the wp_head action.


2

First line of the codex for get_content: Displays the contents of the current post. This template tag must be within The_Loop. Also, this line: <meta property="og:description" content="<?php string_limit_words(the_content(), 15);" ?> /> would need to get_the_content(), as the_content() will output, and you need to return. <meta ...


0

Check for any filters that only return if certain conditions are met. I had an issue once where almost all my pages' content areas were blank. I found the problem was in a snippet of code that looked like this: add_filter( 'the_content', 'this_will_blank_pages' ); function this_will_blank_pages( $content ) { if( is_page( 'some-page-title' ) ) { ...


1

I would create an "Events" custom post type and then create a "Call to Action" custom taxonomy and associate this taxonomy with the custom post type. This way you can have an unlimited amount of events which can be associated with taxonomy terms (your Call to Action). This makes much more sense since you project that you will have few Call to Action types ...


4

You can add code below to the beginning of loop.php add_action('pre_get_posts', 'wpse_change_post_order'); function wpse_change_post_order($query){ $query->set('order','ASC'); $query->set('orderby','date'); } the oldest posts will be in the home page.


0

It is not entirely clear what you are trying to do but sticky posts should be at the top-- that is, the first posts displayed-- already unless you have made an effort to prevent that. That is the default. I just tested this with your query, changing only the category ID to something that exists on my server. To prevent this sticky post juggling-- that is to ...


0

$category = get_cat_ID('animals'); // The Query $args = array('post__in' => get_option( 'sticky_posts' ), 'ignore_sticky_posts' => 1, 'order' => 'ASC' , 'cat' => $category); query_posts( $args ); // The Loop while ( have_posts() ) : the_post(); ?> <div id="sticky_title"><h1><?php the_title();?></h1></div> ...


3

Drawing on Sagive SEO's post this also seems to work without using counters. echo '<ul>'; while ( have_posts() ) { echo '<li><div class="slide">'; the_post(); the_content(); // If there is 1 more post, advance current post and add its content. if ( $wp_query->current_post + 1 < $wp_query->post_count ) { ...


2

Easy using WP query (get to know it...) <ul> <?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=2'); // SET AMOUNT HERE ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><div class="slide"><?php the_content(); ...


1

Manipulating HTML with regular expressions is not a good idea. I suggest you use DOMDocument: // input $html = apply_filters('the_content', get_the_content()); $dom = new \DomDocument(); $dom->loadHtml($html); $blockquotes = $dom->getElementsByTagName('blockquote'); foreach($blockquotes as $blockquote){ foreach($blockquote->childNodes as $e){ ...


0

Maybe you can use a simple preg_replace, but you have to remove spaces around P in this example $result = preg_replace('< p [^>]>(?:\s+|(?: )+|(?:)+)', '', $content); If you will not use any tags inside blockquote, maube you can use strip_tags($content); to remove all html tags


2

AJAX requests (which you imply you are using but do not explain/demonstrate) do not load your active theme, which is where functions.php resides (unless you were referring to a functions.php file that you created in your plugin's directory). As such, your call_user_func() is likely failing as the function that you are attempting to call is not loaded. Note ...


1

You are calling a weird parameter in line 24 which i dont understand... did you copy paste this function from elsewhere? anyhow... change line 24 from: '$param_type' => array($term->term_id), To this: 'cat' => array($term->term_id), Good luck and dont forget to read @toscho comment for future questions.


0

I had that issue as well with creating a new home page with the Genesis Framework. I found an easier solution was to create a new template and choose that template from the page attributes for my home page. Here's some more information.


0

Got it to work! <?php if ( 1 > get_query_var( 'paged' ) ) { ?> <?php if ( is_first_post() ) { ?> first! <br /> <?php the_title();?> <?php the_excerpt();?> <?php } else { ?> <?php the_title();?> <?php the_excerpt();?> <?php } ?> <?php } else { ?> <?php the_title(); ?> <?php ...


1

The shop page is actually an archive page for posts of type 'product'. Its template is in woocommerce/archive-product.php. You need to use the pre_get_posts action to preprocess the query before the loop, conditional_tags to recognize that you are in the product archive page, and a taxonomy query to filter the product categories, which belong to the ...



Top 50 recent answers are included