Tag Info

New answers tagged

1

All thanks to @PieterGoosen's comment, I figured out that this issue was due to a setting within the WPML (multilingual) plugin. Under the 'translation management'->'multilingual content setup' tab of the plugin settings, there is a section for 'custom posts'. In this section, my 'publications' post type was not set for translation, and this somehow ...


1

You are wrongfully handling the WP_Query parameters. You can either use a query string type input or an array based one. Personally I much prefer the array type, so my example uses it: $category_id = (int) $child_category->term_id; $des_post_args = array( 'post_type' => 'tour', 'cat' => $category_id ); $des_post = new WP_Query( ...


2

As an example (adjust to suit your needs): add_action('loop_start', function() { if ( is_single() || is_home() ) echo '<div>'; }); add_action('loop_end', function() { if ( is_single() || is_home() ) echo '</div>'; }); You may need to adjust the conditional statements further if you wish to target archive pages and the like ...


0

If you are using setup_postdata( $post ) you need to use the global $post as for some reason it does not work without that specific variable. Once you manually set $post to a new value, you are altering the $post global, so you will need to reset it back to the current post of the main query. Apart from that, you should never use any global variables set ...


0

There are multiple ways to handle these things and your question is a little light on detail why you need. Specific to the title part — to retrieve title of specific post you shouldn't be messing with globals at all, just do $title = get_the_title( 17 ); or around that. In most of the cases template tags have a version that retrieves data for specific ...


1

Turns out it was the WooCommerce Jetpack Plugin all along. Stupid thing had something enabled which it didn't need. I guess that's what I get if I let a client access the plugin menu. Thank you, denis.stoyanov, for helping me find the solution!


0

There are some plugins that add the next/prev links in <head> and follow Google recomendations for paginated archives, which are similar to recomendations for infinite scroll. If you are interested in doing it at yor own, you can implement the ajax load-more in archive templates and do something like this (not fully tested, just an example): // Print ...


0

You can get the diff between your 2 contents and then add to the first one a given number of words like this (not sure, but give it a try ;) ) : global $more; $more = 0; $content_cut = get_the_content( '' ); $more = 1; $content_full = get_the_content(); // Get the diff $content_diff = str_replace( $content_cut, '', $content_full ); // Get 10 first words ...


1

I generally merge their ID arrays and make a third query. To keep first set of queries cheap I only return their ID's using fields parameter like this: //setup your queries with extra parameter fields => ids $query1 = new WP_Query(array('fields' => 'ids','other_parameters' => 'etc')); $query2 = new WP_Query(array('fields' => ...


0

use % to set the template(style) or you can use :nth-child(16n+1) ... <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php $st = 16; //after how many blocks you want to repeat the pattern <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count%$st == 1) : ?> <div class="style-1"><?php ...


2

Don't concatenate your id values into a comma separate string otherwise you will have to explode() by comma delimiter which is pointless, instead, if you are getting IDs from some other business logic as evidenced in your iteration over $rows, then build an array of IDs as per the following example: $ids = array(); foreach ($rows as $obj) { $ids[] = ...


2

The p (post) paremeter for WP_Query accetps a single value only: $args = array( 'p' => 100 ); For multiple posts use post__in and pass an array of post ids: $args = array( 'post__in' => array(100, 102, 105) ); See Post & Page Paremters for further clarification.


0

There's probably some better way of doing this, but thought i'd give it a go anyways :) - also got some of the answer from here Adding active class to first item <div class="container"> <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Wrapper for slides --> <div class="carousel-inner"> ...


0

If you want to enqueue your files separately use this code and still be able to register them(probably you want to use it after wards as well) then use this: $template_directory = get_template_directory_uri(); $array_of_js_files = array( array( 'script_handle1', $template_directory . '/your_directory/file1.js', array(), //any ...


3

You need to enqueue the scripts as well, not only register them. You can, however, just simply enqueue a script without registering it if you are not going to enqueue it conditionally. I would try something like this: (Untested and requires PHP5.4+) add_action( 'wp_enqueue_scripts', enqueue_scripts, 11 ); function enqueue_scripts() { /** * Build ...


1

If you have Yoast's Analytics plugin, this wouldn't be super hard. However, it will require some coding knowledge. I won't spell everything out for you, but I will point you in the right direction. Without Yoast, you'll have to review Lots of Documentation Load Yoast GA Files/Classes and Analytics ID from Yoast (or use Google Client API itself) Request ...


-1

Eric based on your code I wrote to meet my needs, for those who want to follow: Eric com base em seu código eu escrevi o para atender as minhas necessidades, para quem quiser segue abaixo: <?php global $wpdb; $produto_id = 22777; // ID do produto $consulta = "SELECT order_id FROM {$wpdb->prefix}woocommerce_order_itemmeta woim LEFT JOIN ...


0

As explained in Codex post__not_in (array) - use post ids. Specify post NOT to retrieve. post__not_in argument have to be passed as array. Change your query to: $the_query = new WP_Query( array( 'category__in' => $project_category, 'posts_per_page' => -1, 'post__not_in' => array( $postid ), ) ); And it should work.


0

My approach was also correct but the only problem was we were missing is that resetting the query before the post navigation links. Here is the updated answer. <?php $user_fav = get_user_favorites($user_id); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'posts_per_page' => 4, ...


0

this code is with in the loop of single.php , RIGHT? If so then give this code the try , it should work . Problem with your code seems that you are using showpost, rather you should be using posts_per_page Plus i see this fragments of code like `$test = ""; $test .= ',' . $tag->name; $test = substr($test, 1);` I don't seem to find its use. And ...


1

Harman, don't use get_posts() when pagination is required. You may also accomplish this task using WP_Query. Refer to this answer explained beautifully by Chip Bennett at How to fix pagination for custom loops? <?php $user_fav = get_user_favorites($user_id); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args ...


2

You need to set ignore_sticky_posts to true in your query arguments. This way you exclude sticky posts and only focus on the post ID's array being passed to post_in 'ignore_sticky_posts' => true, EDIT If this does not make much sense, please see my answer here to similar question where I have explained it a bit better. Be sure to check it out THE ...


0

What you are doing is right except that you are careless or you just copied code from somewhere else and pasted in without modifying it. <?php $sticky = get_option('sticky_posts'); if (empty($sticky)) { return; } $counter = 1; $posts = new WP_Query(array( 'posts_per_page' => 5, 'post__in' => $sticky, 'meta_query' => ...


0

this is what worked for me. works a treat. $child_pages = new WP_Query( array( 'orderby' => 'name', 'order' => 'ASC', 'cat' => '41' ) ); while ( $child_pages->have_posts() ) : $child_pages->the_post(); get_template_part( 'content', 'grid-projects' ); endwhile; wp_reset_postdata();


-2

Feito! Realmente com o WP_Query não dá... pra saber essa informação é necessário utilizar 2 tabelas do WooCommerce. Então montei a função pra você... ela busca pelo postID do produto e retorna o objeto dos pedidos pra você fazer o loop normal. É só coloca-la no seu function.php e usa-la em qualquer lugar que quiser! Aqui funcionou bem! Se algo der errado ...


1

The sticky posts are prepended on the first paginated part of the home page, so try this: add_action( 'pre_get_posts', function( $q ) { if ( $q->is_home() && $q->is_main_query() && $q->get( 'paged' ) > 1 ) $q->set( 'post__not_in', get_option( 'sticky_posts' ) ); } ); to remove it from the other paginated parts ...


2

You have to alter the query and add the orderby argument specified as name. I would go for the pre_get_posts action (see documentation) with some conditional tags to select the query for the right page. For example: function change_posts_order($query) { if($query->is_home() && $query->is_main_query()) { // edit to match the desired page ...


0

before (string/array) - Date to retrieve posts before. Accepts strtotime()-compatible string, or array of 'year', 'month', 'day' values: I would try the before parameter with a value of 1 day or 24 hours


2

As birgire said date query is an array of arrays May be this solves your problemo. $args = array( 'post_type' => 'surf_reports', 'posts_per_page' => '1', 'category_name' => $cat (this is pulled dynamically in my template), 'date_query' => array( array( 'after' => '24 hours ago' ) ) );


0

I found a solution which displays the posts ordered by the date value, and also removes the past ones. <div class="container"> <div class="row"> <table> <tr> <th>Artista</th> <th>Fecha</th> <th>Ciudad</th> <th>Información</th> ...


1

No there is no issue you can use query inside a loop with the help of reset post data and query wp_reset_query() - ensure that the main query has been reset to the original main query wp_reset_postdata() - ensures that the global $post has been restored to the current post in the main query.


1

I tested the query and it does work so the only thing I can spot that is misleading but not right is directly after you while() statement you have the_post(). This doesn't work in secondary queries, it should look like: <?php if( $subpages->have_posts() ) : ?> <?php while( $subpages->have_posts() ) : $subpages->the_post(); ?> ...


0

The simplest solution: echo get_the_category_list( ', ' ); Following your way: Change your $args like so: $args = array( 'template' => '%2$l', 'term_template' => '%2$s', ); And then, add this to your functions.php file (this will affect all %l markers!); add_filter( 'wp_sprintf_l', function($templates) { // ...


2

First, let's clean up this tag SPAM nightmare so we can read it and then simplify the code: function adinserter() { return 'abcdefg'; } if (have_posts()) { $count = 0; while (have_posts()) { the_post(); $count++; get_template_part( 'content', get_post_format() ); if ($count == 3) { if (function_exists ('adinserter')) { ...


0

get_the_ID gives you the ID of the current post, but at no point during that loop do you change what the current post is. It's always the last post processed in the previous loop because that's the last time you called the_post(). This is why you always get the same ID. Instead, store the ID: $results[$key]['ID'] = $value->ID; Then echo that instead: ...



Top 50 recent answers are included