Tag Info

New answers tagged

0

use here set type method: for more information please visit below link click here add_action('init','engineCreateRecurringSchedule'); add_action('engineRecurringCronJob','engineDaysToGoUpdate'); function engineDaysToGoUpdate(){ // Arguments to get published posts with 'engine' post type. $engineDaysToGoArgs = get_posts( array ( 'post_status' ...


1

I think the use of meta_query is in order: $user_query = new WP_User_Query( array( 'meta_query'=> array( array( 'key'=> 'birthday', 'compare' => 'NOT EXISTS' ) ) ) ); Basically, this looks for all users where the meta key of birthday doesn't have a value ...


1

User Meta Query with RLIKE: If the birth date is stored like dd/mm/yyyy, in the user meta, then you could find all August birthday users with the following meta query: 'meta_query' => [ [ 'key' => 'birthday', 'value' => '/08/', 'compare' => 'RLIKE' ], ] You could also consider storing the birthday month ...


0

If you use the like comparison operator in your meta query, it should work fine to look inside a serialized array. $wp_user_search = new WP_User_Query(array( 'meta_query' => array( array( 'key' => 'wp_capabilities', 'value' => 'subscriber', 'compare' => 'not like' ) ) ...


1

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


1

You can try this: $query = new WP_Query( [ 'wpse_pid' => 100, // Our custom post id argument 'wpse_compare' => '>', // Out custom compare argument (<,>,<=,>=,!=,<>) 'posts_per_page' => 100, // Modify this to your needs ] ); where we use the following plugin ...


3

You can use 'posts_orderby' filter to change the SQL performed. Note that: using get_posts() you need to set 'suppress_filters' argument of false for the filter to be performed if you don't explicitly set 'post_status' you'll get only published posts (so no much to order) Code sample: $filter = function() { return 'post_status ASC'; }; ...


1

parent is your answer here. Every term have a parent value set in its parent property. This value is an integer value, and represent the term id of its parent term. All top level terms have a value of 0 which just simply means it is a top level term First we need to build an array with parent terms and the specific terms from get_the_category. We will skip ...


0

For a left-sided match you can get around the automatic adding of '%''s by WP by using regular expression RLIKE: 'meta_value' => '^' . preg_quote( $today ), 'meta_compare' => 'RLIKE' Similarly for right-sided match: 'meta_value' => preg_quote( $today ) . '$', 'meta_compare' => 'RLIKE'


0

The simplest way to handle this is to create a page with slug property which will be used to display all properties, and add a rewrite rule to handle requests for property IDs. // add property_id query var to hold ID of requested property function wpd_query_var( $query_vars ){ $query_vars[] = 'property_id'; return $query_vars; } add_filter( ...


0

From what I understand you have a loop that displays up to 500 pages. If the page parent = 18219 than you want to query the tags for that page. As far as I know, by default WP does not allow you to tag Pages, only Posts. But let's pretend you have a plugin that allows you to do that... Inside your loop you can check to see if the page has a parent equal to ...


2

You can try the following (untested) mini plugin: <?php /** * Plugin Name: Support for ignoring the default menu order in WP_Query * Description: Uses the _ignore_default_menu_order argument * Plugin URI: http://wordpress.stackexchange.com/a/193291/26350 */ add_filter( 'posts_where', function( $where, $q ) { global $wpdb; if( (bool) ...


2

pre_get_posts does not explicitely changes the value in the db of posts_per_page, this value stays constant to the value set in the back end under the readings settings. pre_get_posts only changes this value before the SQL query is build in WP_Query right before the main query runs. If you need to get the exact ( more specific ) amount of posts per page set ...


0

Okay, it seemed that going with more than 1 taxonomy was just wishful thinking. I settled with this: CPT still is 'magazine' Hierarchical taxonomy terms were used instead: Parent: The author name Children: The magazines that each author will publish. With the code below I managed to get a working taxonomy-authorname.php page: <?php $taxonomies = ...


0

Try this <?php get_header(); ?> <div id="content" class="clearfix row"> <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article"> <section id="work" class="row"> <div class="span3"> <h3>Recent Work</h3> <p>Intro Lorem ...


2

The WP_Query() only queries posts from the wp_posts table. Even if you add additional parameters such as: 'meta_query' => array( array( 'key' => '_thumbnail_id' 'compare' => 'EXISTS' ) ) It looks at the wp_postmeta table to ensure that the posts it pulls has the post_meta _thumbnail_id but it does not also pull the ...


1

I think the cleanest method here is just run a custom query, get the ID and then remove that post from the main query with post__not_in. You can additionally run a query inside a function and then call the function in your featured section and in pre_get_posts. There is another way, using a global to pass the ID from your custom query to your main query, but ...


0

Try like this $meta_query = array('relation' => 'AND'); if($queryGenre) { $query_genre = array( 'key' => 'genre', 'value' => $queryGenre, 'compare' => '=', ) ; array_push($meta_query,$query_genre); } if($queryMood) { $query_mood = array( 'key' => 'mood', 'value' ...


2

Here is an answer I recently did on another question, the same as your. Because the answer was never upvoted or accepted, I could not mark this question as duplicate, so I have deleted the answer in the other post and reposting it here. Please note, some points are not aimed at this issue and can be ignored, also, you will just need to make a few ...


1

One problem with the query is that the self-join with the ambiguous WHERE gives you a crossed dataset (which is masked by the DISTINCT), so it would be simpler to use wp_post as a base to attach the joins that precisely match the keys, eg SELECT p.ID, key1.meta_value as prog_ongoing, key2.meta_value as prog_date_start FROM ...


1

I pretty sure this filter lets you add an array of variables. I've not tested this: function add_custom_query_vars( $vars ){ $vars[] = "variable1"; $vars[] = "variable2"; $vars[] = "variable3"; //... etc return $vars; } add_filter( 'query_vars', 'add_custom_query_vars' ); Or another way of doing it would be to do this: function ...


-1

Set 'posts_per_page' to 1 on your args variable. I also suggest that you add 'page-attributes' while registering the magazine's post type and order the result by 'menu_order'. This way, you will have the field Order while editing a magazine, and set the highest which should appear on this query.


1

By seeing your code, you are creating the $args array but not passing it to the WP_Query. Try using the below way. $args = array( 'posts_per_page' => 7, 'offset' => '5', 'paged' => $paged ) ; $my_query =new WP_Query($args); ......


1

Please find the code its working you need to just add the js and css for your design it will add three custom post and add widget to the widget area you can drag and drop it in any side bar. <?php /** * Plugin Name: Custom Tabbed Plugin * Description: This is testing of the custom tabbed plugin * Version: 1.0.2 * Author: ...


1

First pass for a solution. It uses the new meta sorting that was introduced in 4.2: <?php $args = array( 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', 'ongoing' => array( 'key' => 'prog_ongoing', 'value' => 1 ), ...


0

You're correct in your approach. If you post your code will be better, but something like this: $args = array( 'post_type' => 'project', 'tax_query' => array( array( 'taxonomy' => 'region', 'field' => 'slug', 'terms' => $region, //set your region ), ), ); $the_query = new ...


0

Why not use WP_Query()? Lot simpler this way: <?php $args = array( 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'prog_ongoing', 'value' => 1 ), array( 'relation' => 'AND', ...


0

You can use either GET or POST requests to achieve that functionality without using any AJAX (which, in fact, does the same but uses JS to process requests). You need to add ?name_of_var=value after trailing slash on labels that link to different queries. Basically, your 'Coca-Cola' link has to look this way: site.com/products/?brand=cocacola After that, ...


1

This is default behavior when the post__in parameter is used. If you read the docs, you will see that you should set 'ignore_sticky_posts' => 1 to eliminate sticky posts being queried EDIT Your query arguments should look like this $recommended_args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'post__in' => ...


0

I changed my approach in the end. I just called a single query and added the logic to check the date of the last post was in a different month: $today = date("r"); $articledate = get_the_time('r'); $difference = round((strtotime($today) - strtotime($articledate))/(24*60*60),0); if ($month_sort == true ...


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


3

You need to get the post ids from the original main query and exclude them. Then you should remove your offset from your custom query. That should do the trick. Random ordering basically ignores the offset parameter, so you need to explicitely remove the posts from the query to exclude them You can use wp_list_pluck() to get an array of post ids from the ...


0

here is the mysql query you can use to get the result having distance less then your value. SELECT * , pm1.meta_value as latitude, pm2.meta_value as longitude , (((acos(sin(([latitude]*pi()/180)) * sin((pm1.meta_value * pi()/180)) + cos(([latitude]*pi()/180)) * cos((pm1.meta_value * pi()/180)) * cos((([longitude] - ...


0

It seems that you could use Types and Views plugins (with Views "Parametric search" feature). Views is commercial, but unless you are building your personal website, I think it's worth it. Nice writeup about those plugins is, for example, here: http://www.neilcurtis.me/guides/best-wordpress-plugins/


0

It doesn't look like you're passing your search query in your WP_Query args. To do this on a custom search page try the following: Replace this: $the_query = new WP_Query('post_type=darpe-entries'); With this: global $query_string; $query_args = explode("&", $query_string); $search_query = array(); foreach($query_args as $key => $string) { ...


2

It is quite hard to properly answer your question with the amount of context in your question, but I am going to try to use the context from your previous question Having a bit more context here on template, and if I read this correctly, this is on your index.php, I still believe and stand by my point that pre_get_posts is your answer. Tackle this problem ...


0

I couldn't solve this issue but found a workaround : I get my issue ID on parse_request hook and use it in parse_query (I created a class with an $issue_id var, but global variable should be fine too). Still don't know why you can't use WP_Query directly in parse_query, but I opened ticket on Posts2Posts github : ...


5

You need to define your arguments before you pass them to WP_Query, not after. Also, your meta_query should be an array of an array, not just an array This $query = new WP_Query($thumbs); $thumbs = array( 'meta_query' => array('key' => '_thumbnail_id') ); should look like this $thumbs = array( 'meta_query' => array( ...


1

You can do this by checking the number of results returned by your query. Try this. <?php $rawfiltertag = get_post_meta( $post->ID, '_cmb_client_name', true ); $filtertag = sanitize_title( $rawfiltertag ); // wp_query arguments $args = array ( 'post_type' => 'post', 'meta_query' => array( array( ...


1

You are invoking an infinite loop, because you are calling WP_Query inside WP_Query, which is where the hook resides, so you are hooking it into parse_query over and over again. To avoid it, put the following at the beginning of your callback function: // avoid infinite loop remove_action( 'parse_query', __FUNCTION__ ); Additional note, it might just be ...


2

query_posts - You should never ever use query_posts. Apart from what @Rarst has said, the really big issue with query_posts is, it breaks the main query object ( stored in $wp_query ). A lot of plugins and custom code relies on the main query object, so breaking the main query object means that you are breaking the functionalities of plugins and custom code. ...


0

I din't try this. But what about making a function for fetching the issue_id? And remember, wp_reset_postdata() for a WP_Query() is important. function get_the_issue_id() { $issues = new WP_Query( /* .... */ ); $issue_id = $issues->get_posts()[0]->ID; wp_reset_postdata(); //it's important return (int) $issue_id; } Now do the parse_query ...


3

Note that the posts_orderby filter is not available for get_posts() where suppress_filters is true by default. You can use WP_Query instead: $args = [ 'posts_per_page' => 1, 'orderby' => 'rand', 'post_type' => 'listing', 'ignore_sticky_posts' => true, ]; add_filter( 'posts_orderby', ...


0

Try to use following code:- <?php function force_random_day_seed($orderby) { $seed = floor( time() / DAY_IN_SECONDS ); $orderby=str_replace('RAND()', "RAND({$seed})", $orderby); return $orderby; } add_filter('posts_orderby', 'force_random_day_seed'); $temp_value = get_option(current_time('Y-m-d')); ...


0

Small changes in your code: //$id = get_the_title(); $title = '"The Man Who Wants You" – Amos Lee'; //$posttags = get_the_tags(); $posttags = array('AMOS LEE', 'FOO FIGHTERS', 'TAYLOR SWIFT'); $matched_tags = array(); if ($posttags) { foreach ($posttags as $tag) { if (stripos($title, $tag) !== false) { array_push($matched_tags, ...


0

It's a bit hard to answer with not much information, but here are some things you can try and ask yourself: Reset your permalinks (Settings > Permalinks > Save Changes) What happens when you set WP_DEBUG to true in your wp-config.php file? Is this a custom post type, or was anything recently changed that may have caused this?


4

You would rather want to use the post ID inside the loop to target your pages. is_page() simply checks whether the current page is actually a page or a specific page if a value is passed Example if ( $post->ID === 7 ) { // Do something for page id 7 } else { // Do something for other pages }


0

Ok, the problem was with my radio buttons. <?php foreach( $regions as $region ) : ?> <label><input type="radio" name="region" value="<?php echo $region->slug;?>" /><span><?php echo $region->name;?></span></input></label><br /> <?php endforeach;?> I have solved this problem by giving ...


1

Put this in your loop: <?php $title = get_the_title(); $posttags = get_the_tags(); if( $title && $posttags ) { $result = find_tag_in_title( $title, $posttags ); var_dump( $result ); // dump result } ?> Put this in your functions.php file: <?php function find_tag_in_title( $title, $posttags ) { foreach( $posttags as $tag ){ ...


0

I really do think that my-sticky is not actually your term's name, but actually the slug. Usually, multiple words in the term name is separated by spaces, and the first letters are capitilized. Slugs are all small letters with multiple words separated by hyphens. So I would change name to slug in get_term_by(). Just one note, with multiple taxonomies and ...



Top 50 recent answers are included