Tag Info

New answers tagged

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'); ?>


0

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 ...


0

I did something like this when making custom reports for WooCommerce since the data was in tables not part of WordPress. My advice to you as well, I can't tell all that you're trying to accomplish here but research WP_Query a lot because most any WordPress query can be accomplished with it and ONLY if it cannot be done should you consider using a $wpdb ...


3

Just for information, this is a bug in WP and autop. You can view the ticket here and it does not look like it will be fixed any time soon. The work around is to start your multiline comment with <!-- and end it with <!-- -->


0

The best approach IMO is to count the posts returned per page against the set posts_per_page option set in your query. If the count is less than the set posts_per_page, calculate the difference and then use this as the amount of posts to fill the rest in a custom query This is how it should work: First, count the amount of posts returned by your "main" ...


0

As noted by @s_ha_dum, I had some sticky posts. I had to use the 'ignore_sticky_posts' => true argument inside the WP_Query.


1

Well first of all, that tutorial is "doing it wrong" in the AJAX department. WordPress has an AJAX API, which should be used in this case. That said, the basis of your problem is this: $args = array( 'posts_per_page' => $numPosts, 'paged' => $page ); Those are your query arguments for the posts you're requesting. Note that there's nothing ...


0

which gives me all posts inside the tax inspiration - I need to alter this, so that I get only selected ID's in my array, ex. 4714, 3608, instead of all terms of the tax. I'm assuming you mean that this query gives you all posts inside post type inspiration and you want to pull specific post IDs instead of all posts of the post type. Taxonomies and Post ...


0

You'll need a loop before you get to your sidebar loop to initiate your unique values. You could run the same loop twice, with rewind_posts() between the two loops ( so you get your original loop, starting from index 0 ). In your first loop, loop through and add all your values to an array so that the array looks something like this: Array( [0] => ...


0

This is a bit messy to do in MySQL, given the lack of a preg_replace - the following uses a nested REPLACE to strip all numbers from the title: function wpse167989_posts_orderby( $orderby, $query ) { global $wpdb; // Strip all numbers from title, and trim any leading spaces. return $wpdb->prepare( 'LTRIM(' . str_repeat( 'REPLACE(', 10 ...


0

The problem probably comes from whenever a $post has no terms set. You need to set $brand = array() outside your IF statement, add it just under get_the_terms(). At that point it also wouldn't hurt to wrap your switch statement in a if( ! empty( $brand ) ) { Another problem I see with this code is that you're adding your term IDs to an array, then ...


1

I suggest just making a new Post Type with the default Wordpress register_post_type(). function create_my_post_type() { $labels = array( 'name' => __( 'Providers pricing', 'myplugin_namespace' ), 'singular_name' => __( 'Provider pricing', 'myplugin_namespace' ), 'menu_name' => __( 'Provider Pricing', ...


6

There is a sad truth: you can never ever be sure that some code will not break your code, and there is nothing you can do to prevent that. Expecially in WordPress where everything is global. That said, yes, global $post is one of the most used global var, so using special care for it can be a good idea. In my code I rarely direct access to global $post. ...


1

I'm not in the position to code right now, but here is an idea A thousand posts is quite a lot, but it is even more if you are retrieving all posts from the db in one go. What if you have ten thousand posts, of which only ten or twenty is not tagged after the whole retagging operation. This can become such a huge query that you run the danger of timing out ...


0

Well, I found out what it was. Actually I think this might be caused by a bug in Wordpress (or perhaps one of the add-ons I'm using). In the content editor I had blocked out some of the code with "". For some reasonthe closing markup "-->" didn't get registered, so in the code anything after the_content(); got blocked out.


0

Try this: <?php $acf = false; while ( have_posts() ) : the_post(); if( have_rows('boxes') ) $acf = true; the_content(); if( $acf == true ): echo '<p>This is only shown when the_content() is removed.</p>'; else : // no rows found endif; endwhile; ?> This is ...


0

Some thoughts on how I would approach this. I can update later with some code if necessary when I have the time. I would handle the first page with two additional queries, so three loops on page one. Hook pre_get_posts and do two meta queries for the three posts that will appear in the first two loops. Those will be cached for later when you display them on ...


0

I've finally solved it by adding the following code at the end: <?php // Find connected pages $performer = new WP_Query( array( 'connected_type' => 'place_your_p2p_connection_here', 'connected_items' => get_the_ID(), 'nopaging' => true, ) ); // Display connected pages if ( $performer->have_posts() ) : ...


2

This can be done with a very short plugin. function posts_on_home_page( $posts_per_page ) { if ( is_home() ) return 5; return $posts_per_page; } add_filter( 'pre_option_posts_per_page', 'posts_on_home_page' ); This is actually pretty close to the Codex example for pre_option_(option_name).


0

Most pagination relies on the $wp_query global. Try changing $loop to $wp_query And put this wp_reset_postdata(); after the endwhile.


2

You might be running up against WordPress's global $blog_id variable in test case #2. Try this: foreach($sites as $my_blog_id => $name) { switch_to_blog($my_blog_id); $sites[$my_blog_id] = get_bloginfo('name'); restore_current_blog(); }


0

Use the meta_query argument of WP_Query. For example, if your custom field name is "year" and you want to get the post with year=2013: <?php $loop = new WP_Query( array( 'post_type' => 'Sport', 'posts_per_page' => 3, 'meta_query' => array( 'meta_key' => ...


2

Take a look the section called Preserving Existing Query Parameters on http://codex.wordpress.org/Function_Reference/query_posts Try merging in the existing query parameters; they might be getting overridden. Instead of: <?php query_posts('cat=4'); ?> try global $query_string; query_posts( $query_string . '&cat=4' );


0

Ok, so I fallow your way and I create page Make Sticky with page template. Then i change some.. I created link using this function: <?php if( current_user_can('editor') || current_user_can('administrator') ) { ?> <div class="manage"> <a href="<?php echo add_query_arg( array( '_post' => get_the_ID() ), ...


0

What you are trying to accomplish here is will not work just but calling the function make_sticky on a link because this function doesn't actually print anything for the final user to take an action. What will happen here is that every post in the loop will get set as sticky every time that method is called. So to resolve your issue you want to create a ...


0

Following Bordoni's lead, and with a bit of trial and error, finally got it working <?php $the_query = new WP_Query( array ( 'posts_per_page' => '10', 'category_name' => 'books' ) ); while($the_query->have_posts()) : $the_query->the_post(); ?> @Bordoni - Thanks for the hint!


3

Lets start by removing the query_posts() from your code since you already have it's better brother new WP_Query. Then what you will need is to use the category_name param on your WP_Query. You should always search on the WP_Query page before you ask here, you can find more referencers there. Here is how @speedypancake resolved the issue: <?php ...


1

When the instance of WP_Query is not a variable on the PHP file you are working on it tends to be the "main" query and to edit this instance of the WP_Query you will need to Hook to the pre_get_posts action and change what you need there. Here is an Exemple: <?php add_action( 'pre_get_posts', 'q166401_pre_get_posts', 10, 1 ); /** * On this case I will ...



Top 50 recent answers are included