New answers tagged

1

Strange that stickies aren't completely unset from the main loop on paged pages but only on the first page. If we look at the source, we will see that stickies are only unset from the main loop if they are on the first page. So we have two options here depending on what you exactly need OPTION 1 If you need to keep your stickies in the loop on paged pages ...


2

This Plugin gives you a list of posts for each Site already, but it does not exactly do what you want to do. Basically, it gives you a list of all posts in your network. What you need to do afterwards is sort them by site_id and create an output for that. I do not know if this is the best version - but as WP_Query returns an one-dimensional array, you need ...


0

Add this code to your functions.php function mdc_remove_img($content) { $content = preg_replace("/<img[^>]+\>/i", "", $content); return $content; } add_filter( 'the_content', 'mdc_remove_img' );


-4

I figured out how to do this, Instead of using the_content(); Im now using the_excerpt(); and Im just changing the amount of characters it brings through!


2

To answer your first question What is the difference between those functions get_terms() returns an array of terms objects that belongs to a specific taxonomy get_the_terms() returns an array of terms belonging to a post the_terms() displays an HTML formatting string of term names belonging to a post Because you need your terms not hyperlinked and ...


-1

You should use get_the_terms() or get_terms() because the_terms() echo/prints the results and get_the_terms() or get_terms() only get value and save it to variable or memory. An possible example is foreach($posts as $post){ $term= get_the_terms($post->ID, 'category' ); echo 'Category: '.$term; } You may need to use another loop to handle ...


0

There are 4 arguments that might help you with wp_nav_menu(): before – "(string) Text before the link text." after – "(string) Text after the link text." link_before – "(string) Text before the link." link_after – "(string) Text after the link."


0

I got it! For any one in the future with the same problem: ACF's get_field_object() apparently makes a WP_Query and doesn't clean up after so, since I called it for every post, I always got the same post after a certain point in the elaboration. I found the solution in this question. Some code for clarity: <?php while ( $query->have_posts() ) : ...


0

Just loop over WP_Query::$posts to get the titles: $option_posts = new WP_Query( [ 'post_type' => 'organisationer' ] ); $options = []; foreach ( $option_posts->posts as $post ) { $key = "option_{$post->ID}"; $options[ $key ] = apply_filters( 'the_title', $post->post_title ); } woocommerce_form_field_radio( 'custom_field', ...


0

Have you tried using wp_reset_query() before the loop.


2

Use strtotime to compare dates. $start = strtotime('yesterday'); $end = strtotime( '+1 week',$start); $args = array( 'posts_per_page' => 5, 'ignore_sticky_posts' => 1, 'meta_key' => 'sw_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'date_query' => array( 'after' => $end, ...


0

I found the solution to this was in the $wp_query variable. By getting the global variable for this and overriding the values within it i was able to have full control over what displayed on the page. This allowed me to generate a WP post object that came from a database outside of wordpress, but didnt have to do anything difficult to make it display. Here ...


-2

If you are looking for plugin then this is simple way to install Plugin: WordPress Popular Posts Add Shortcode to sidebar: [wpp range=weekly stats_comments=0 thumbnail_width=30 thumbnail_height=30 thumbnail_selection=usergenerated do_pattern=1 pattern_form={image}]


5

You are returning inside your loop - so it returns on the first iteration, giving you one result only. You should build a string inside your loop instead, and only return when the loop is over. Something like $featured_properties = ''; if( $featured_query->have_posts() ): while( $featured_query->have_posts() ) : ...


2

This is quite basic but should help you on your way. //Get posts for the current week $args = array( 'date_query' => array( array( 'year' => date( 'Y' ), 'week' => date( 'W' ), ) ) ); //Check for search query if ( isset( $_GET['s'] ) ) { $args['s'] = $_GET['s']; } //Create these variables for ...


0

Yes you need some arguments defined. A good place to easily get your loops defined is: https://generatewp.com/wp_query/ Here's an example of some arguments used. // WP_Query arguments $args = array ( 'post_type' => array( 'post' ), 'nopaging' => true, 'posts_per_page' => '3', ...


1

There is no $post var local to your function, you need to use global $post first, or get_the_ID(). get_post_meta( get_the_ID(), '_cf_address', true );


4

If you need to: page the query retain 12 posts per page instead of "sticking" the desired posts on top of the required 12 only need to show those posts on the first page you can try the following $ids_args = [ 'post_type' => 'products' 'posts_per_page' => -1, 'orderby' => 'meta_value_num', 'meta_key' => ...


4

We could do that with two queries: First we fetch the post ids we need with the first query and then we merge it with our sticky post ids and feed it into the second query, using the post__in parameter for filtering and ordering: $args = [ 'post_type' => 'products' 'posts_per_page' => 12, 'orderby' => ...


0

There is some changes in code try this $query = new WP_Query(array( 'tag' => 'php' )); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); the_content() ; endwhile; endif ;


1

It is not recommended to use query_posts. But this is not the problem, Problem is you are using PHP variable in single quotes. 'tag=$tag' Consider these examples: query_posts('tag=php'); //OR query_posts("tag=$tag"); //$tag should output: php Using WP_query //Recommended $query = new WP_Query(array( 'tag' => 'php' )); Ref: WP_Query-Tag_Parameters ...


4

Use pre_get_posts to alter the main query before it is run. The action runs on every query, use the Conditional Tags to target specific queries. function wpd_sort_by_meta( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'meta_key', 'your_meta_key' ); $query->set( 'orderby', ...


1

It is quite hard to understand what you need to do here, but you need to look at the following Do not use the global variables as local variables, it breaks the global variables and causes issues with the loop. It is also quite hard to debug when you run into issues. The only global variable that should be used as a local variable is when you work with ...


1

You don't need a custom query to include CPTs in homepage posts in normal cases. Just use pre_get_posts. function wpse215208_include_all_cpt( $query ) { if ( is_home() && $query->is_main_query() ) { $query->set('post_type', array( 'post', 'photo', 'video', 'web' ) ); } } add_action('pre_get_posts', ...


1

I've found the solution. According to https://codex.wordpress.org/Function_Reference/the_content#Overriding_Archive.2FSingle_Page_Behavior, one must add global $more; $more = 0; before the call to the_content(). So now my inner loop reads: <?php $recent_posts_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 5)); while ...


0

Solved i changed for each loop <?php $taxonomies = array( 'urun-kategorileri', ); $args = array( 'orderby' => 'menu-order', 'order' => 'ASC', ); $tax_terms = get_terms($taxonomies, $args); echo '<table class="table table-hover"><tr>'; foreach ...


0

You skip to the else part in after the 4th run of your foreach. Put the $i++ at the end of the loop and your fine. foreach( $tax_terms as $tax_term ) { if( $i <= 4 ) { echo '<td><a href="' . esc_attr( get_term_link( $tax_term, $taxonomy ) ) . '" title="' . sprintf( __( "Profilleri Görüntüle %s" ), $tax_term->name ) . '" ' . '>' ...


2

You could make use of the WP_Query property $current_post $current_post (available during The Loop) index of the post currently being displayed. It can be used for your purpose.


2

the permalink and post title won't be available until after you've run the query. the following should return the last 3 posts from the designated category. the same post is being displayed 3 times because it doesn't look like you're setting the permalink or post title from within "the loop" if (!function_exists('get_posts_menus')): function ...



Top 50 recent answers are included