Trying to get property of non-object in shortocde
You need to call global $post before using $post->ID, or better, use get_the_ID() instead.
You need to call global $post before using $post->ID, or better, use get_the_ID() instead.
This is more php, but you can use in_array(). Just check if the current post type is in array in $hide_sidebar. You can do the following $hide_sidebar = array(‘example1’, ‘example2’, ‘example3’); //hide sidebar on these post types if ( in_array( get_post_type(), $hide_sidebar ) ) { // Do something if the post type is in array … Read more
If you look at wp_get_archives() you will notice that the link is generated by get_archives_link(). That function supplies a filter that will allow you to replace the parens. This is fairly crude but does work. function archive_link_wpse_183665($link) { $pat=”|\(([^)])\)</li>|”; // preg_match($pat,$link,$matches); // var_dump($matches); $link = preg_replace($pat,'[$1]’,$link); return $link; } add_filter( ‘get_archives_link’, ‘archive_link_wpse_183665’ );
Here is my own solution. In my html I’ve assign id to all the item and inside the form I’ve added an input option where I pass the value through the script and it was saved later. Simple… script jQuery(document).ready(function($){ $(“.sortable”).sortable({ connectWith: ‘.sortable’, receive: function (event, ui) { document.getElementById(‘hello1’).value = myFunction(); }, out: function (event, … Read more
Use $wpdb->get_col. It will return a one-dimensional array that you can use in post__in $allposts = $wpdb->get_col(“SELECT `music_id` FROM `custom_table` ORDER BY id DESC LIMIT 5”);
Your function is unreliable and totally overboard and really really expensive. Furthermore, as already stated by @MarkKaplun, you are not calling the_post() which causes the $post global not to be updated to the current post being looped through, so the value from get_post_meta() will always have the same value. Although $post_id might work, it is … Read more
You aren’t constructing the meta_query correctly. It is close but not quite right. $searchArray = array(); $searchArray = array(‘relation’ => ‘OR’,); // here is the change // loop over checked checkboxes if(!empty($_POST[‘course_location’])) { foreach($_POST[‘course_location’] as $check) { // echo ‘<h1>’.$check.'</h1>’; $searchArray[] = array(‘key’ => ‘course_location’,’value’ => $check,’compare’ => ‘LIKE’,); } } As you have it … Read more
I cannot really see doing this than to run a couple of queries here, one per category. We will need to be clever here to avoid a lot of unnecessary work. Lets look at the code; (which I will comment to ease the process of understanding) // Get the categories. We will only get the … Read more
Add ‘fields’ => ‘ids’ to skip setting up the post and just create the array you want in the foreach. $week_args = array( ‘posts_per_page’ => – 1, ‘post_type’ => ‘post’, ‘post_status’ => array( ‘publish’ ), ‘fields’ => ‘ids’, ‘date_query’ => array( ‘before’ => ‘next Saturday’, ‘after’ => ‘last Monday’, ), ); $week_array = get_posts( $week_args … Read more
How about using a standard for loop instead: $sunnytags = get_tags ($tagargs); $count = count ($sunnytags); for ($i = 0; $i < ($count < 15 ? $count : 15); $i++) { $string .= ‘<a class=”tag2″ href=”‘. get_tag_link ($sunnytags[$i]->term_id) .'”>’. $sunnytags[$i]->name . ‘</a>’; } And then later, whether you re-run the query or (better still) save … Read more