How to split the loop every 2 and 5 results? [closed]

Yes you can do that using $wp_query->current_post inside the loop. It returns the current posts index number inside the loop (starting form 0). Have a look at the following code block <?php global $wp_query; while(have_posts()){ the_post(); the_title(); //do your other stuff if($wp_query->current_post==1){ //do what you want to do after 2nd post }else if($wp_query->current_post==5){ //do what … Read more

Help with if/else loop [closed]

You arent clear where you want your else statement, so Ive added one for each of the if’s you included. <?php $post_type=”post”; // <– Post Type $tax = ‘temporada’; // <– Taxonomía $termino = get_terms($tax); $category = get_the_category(); $cat_name = $category[0]->cat_ID; if ($termino) { foreach ($termino as $temporada) { $args=array( ‘post_type’ => $post_type, “$tax” => … Read more

Woocommerce linking variations

I found a solution with a recursive function function decomposePrice($base, $iValue, $values, $prices) { $d = array(); foreach ($prices as $i => $p) { $baseP = “$base{$values[$iValue][$i]}|”; if (!is_array($p)) { $d[$baseP] = $p; } else { $d = array_merge($d, decomposePrice($baseP, $iValue + 1, $values, $p)); } } return $d; } $decomposePrice = decomposePrice(“”, 0, $v_values, … Read more

How to create a loop that will display one post and stop?

query_posts() can alter the WP query even when it is executed and it should be placed at least before you start the loop i.e. have_posts(). Currently you are placing it after setting up post data i.e. the_post(). Which is resulting in unexpected behavior. Example: global $query_string; //Get current query arguments query_posts($query_string.”&featured=yes”); if (have_posts()) { while … Read more

How to create a loop where loop changes every post?

The PHP modulus operator gives you the remainder from dividing 2 numbers. The remainder from the division of any number by two is either 0 or 1, so we can use that to provide an “alternator”. We use the current_post var as a counter, which is available in any WP_Query object: while( have_posts() ){ the_post(); … Read more

How to store wordpress title in a variable

You’re example is totally unclear. What is ngegrab, what is $unity, $yesPage and what do you mean with “WordPress title”? Short: what are you trying to do exactly? To get the title of a post, use get_the_title() as mentioned in the other answer. To get the document title (<title></title>), use wp_get_document_title().

WordPress Not Sorting By Custom Field

Please read the documentation. ‘rating’ is not a valid value for orderby. To sort by a custom field you need to use ‘orderby’ => ‘meta_value’ or ‘meta_value_num’. Note that a ‘meta_key=keyname‘ must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)