Tag Info

New answers tagged

0

In wordpress for get random post you have a option with 'orderby' => 'rand'


1

After hours and hours I finally figured it out. I only had to replace wp_reset_postdata(); with $cust_loop->reset_postdata();


0

I've made it this way pretty nicely :) <?php $args = array( 'posts_per_page' => 4, 'category_name' => 'xyz', 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post_status' => 'publish' ); ?>


0

The Sphinx Search website lists three wordpress plugins on its Plugin Page. Maybe one (or more) of them does what you want? Voce Connect. Wordpress Plugin. Ivinco. Wordpress Plugin. Gigaom. Wordpress Plugin. Filters WordPress' core WP Query to allow interoperability with and improve performance of other plugins and existing queries, including core ...


2

This is not that complicated, here is a code snippet that will get you started: if(is_user_logged_in()) { //We only need these products to check $products_to_check = array(81,82,83,84); $customer_bought = array(); //Get all orders made by the current user in the last 365 days $customer_orders = get_posts( apply_filters( ...


1

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


0

with your code, you have this : +++++++++++++++++++++++++++++++++++++++++++++++++++ attribute_color = C1 attribute_fabric = F1 attribute_fabric = F2 +++++++++++++++++++++++++++++++++++++++++++++++++++ attribute_color = C2 attribute_fabric = F1 attribute_fabric = F2 +++++++++++++++++++++++++++++++++++++++++++++++++++ attribute_fabric = ...


0

You should use get_the_categories() Returns an array of objects, one object for each category assigned to the post. This tag may be used outside The Loop by passing a post id as the parameter. $categories = get_the_categories(); var_dump( $categories );


0

You will need to learn the very basics of how Wordpress works and how templates interact to display content. Your question is rather broad looking at your actual problem. In short, a basic template should look like this <php get_header(); if ( have_posts() ) { while ( have_posts() ) { the_post(); get_template_part( 'content' ); } ...


0

Since you know your target post ID (302), you may find useful this shorthand syntax that you can use out of the loop (though its performance is pretty much the same as in any other alternative method:) echo(get_post_field('post_content',302));


0

I think the issue is with the following line of code: $post_thumbnail_id = get_post_thumbnail_id($post->ID); It should be the ID of your $recent variable not $post. $post_thumbnail_id = get_post_thumbnail_id($recent->ID); or $post_thumbnail_id = get_post_thumbnail_id($recent['ID']); and to get a specific size of thumbnail you could do ...


0

Initially, I saw the double and single quotes all jumbled up. This did fix some of what I saw, but I finally had time to test the code you put up. First step, I used var_dump on $recent_posts to make sure I was getting the usable values. Next, I echoed each variable as it was called, to make sure I knew what was being generated. I discovered that this ...


0

Flexbox is an easy way to do this. <div class="row"> <div class="col">...</div> <div class="col">...</div> </div> CSS: .row { display: flex; /* equal height of the children */ } .col { flex: 1; /* additionally, equal width */ } You can find some other methods here: ...


0

I managed to sort the problem out myself with a fresh set of eyes but thought it would be useful for others if they find themselves with a similar issue in future. If the answer needs tidying please feel free to suggest any edits. I had to edit a few lines of code in order to resolve it but here is the complete block again. Firstly I had to add in an ...


0

This question is more of a js/jQuery is then WordPress. I am not going to post a working answer as It is hard to read the html given. And I think how you are doing it is not a effective solution. My answer should guide you towards better solution. First of all you do not need to fade in all element inside the popup. Only fade in the parent and hide the ...


1

Please try the following javascript you need to add class to a tag for read more <a class='readmode'>Read More</a> $('.readmode').click(function() { $(this).siblings('.pop').slideToggle(); return false; }); Here is the demo http://jsfiddle.net/fvcvyc1e/4/


0

There are two popular solutions for this. You can: Alternative 1: Add a counter to the while, and do something special if the counter reaches 3: $i = 0; while(...) { $i++; if ($i == 3) { ... $i = 0; } } This is difficult to do here because you will probably end up with an empty or unclosed li. Alternative 2: Use get_posts instead of ...


0

Here is the code which you can get it show first 10 on left and after that show right side <div class="headlines" data-interval="<?php echo ($interval>0)?$interval*1000:'false'; ?>"> <ul class="headline_left"> <?php $i = 1; while ( $r->have_posts() ) { $r->the_post(); ?> <li> ...


1

You will need to create css classes for a left and right column (you can use bootstrap if you like) after creating the classes try this <div class="headlines" data-interval="<?php echo ($interval>0)?$interval*1000:'false'; ?>"> <ul> <?php $i = 0; while ( $r->have_posts() ) { $r->the_post(); ...


0

Yes, it is quite simple, you just need to work in PHP. Consider you have 36 posts in a loop. $div_html_1 = ''; $div_html_2 = ''; $div_html_3 = ''; $div_html_4 = ''; $div_html_5 = ''; $div_html_6 = ''; if ( have_posts() ) { while ( have_posts() ) { if( category of post == division 1 ) { $div_html_1 .= "Your HTML ...


2

SOLUTION: I added $titles = array(); at the top (outside the loop). Then, within the loop, I used array_push( $titles, get_the_title( $ID ) ); to collect the titles. Then I just checked the array for a matching title before displaying, like this: if ( !in_array(get_the_title( $ID ), $titles ) ) ...then do this And it works!


0

Just wanted to share a link that helps explain comments contained in the answer: http://solislab.com/blog/5-tips-for-using-ajax-in-wordpress/ Here's tip 1 mentioned in one of the comments: USE WP_LOCALIZE_SCRIPT() TO DECLARE JAVASCRIPT GLOBAL VARIABLES Although wp_localize_script() is created for localization, it also has another great use. You can ...


3

You have custom filter in a plugin or in your theme that is messing with WP_Query. Your issue is that something is setting is_home to false. This is not default behavior, by default, is_home should return true in any custom instance of WP_Query. is_home is one of the contributing factors which is responsible for setting up sticky posts at the top in a ...


2

Don't run a new query for your CPT at every iteration of the main Loop. Pull it once, outside the Look with 'posts_per_page' => 4 then increment it as you go. In other words: $counter = 1; $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 20 ) ); $inner_query = new WP_Query( array( 'post_type' => ...


0

display_schools($string); function display_schools($string) { $counter = 0; $i = 0; $len = count($string); foreach($string as $school) { if($counter == 0) { echo '<div class="row">'; } ?> <div class="col-xs-2"> <img src="<?php echo $school['photo']; ?>" ...


0

I found out a way to do this , turned out to be kind of easy here is what i did $Aschools = get_post_meta( get_the_ID(), 'american_member_schools_field', true ); $i = 0; $entries = count($Aschools); foreach ( (array) $Aschools as $key => $Aschool ) { $logo = $Aname = ''; $i++; if ( isset( $Aschool['name'] ) ) $Aname = $Aschool['name'] ...


1

I needed to get post with type event and the custom field "date" later than today, this sample of code worked perfectly for me, I hope it helps to someone in a similar situation. $today = date("Y-m-d"); $today1 = date("Ymd", strtotime("$today")); $custom_meta = array( array( 'key' ...


0

Another way to code it based on the solution by @chittaranjan add_filter( 'the_content', 'remove_autop_for_image', 0 ); function remove_autop_for_image( $content ) { global $post; if ( is_singular('image')) remove_filter('the_content', 'wpautop'); return $content; }



Top 50 recent answers are included