Tag Info

New answers tagged

0

It's not the plugin that is causing the issue it is the fact you are not querying the database correctly. It is not looking for integers your value is currently being stored as a string. To fix this you need to somehow change the value to a integer before it is passed to your array.


0

I found the answer. I had searched high and low yesterday, but today I finally found it: http://wordpress.stackexchange.com/a/143837/10595 add_action('template_redirect', function() { if ( is_singular('posttype') ) { global $wp_query; $page = (int) $wp_query->get('page'); if ( $page > 1 ) { // convert 'page' to 'paged' ...


0

Here's an alternate approach of filtering the posts after the query using whether the wp_get_attachment_thumb_url() returns an empty string to determine if the post has a thumbnail (featured image). //get all the posts however your query does it. simple example when there aren't a lot: $args = array("nopaging" => true); $posts = (new ...


1

$post_count is a WP_Query variable. You need $the_query->post_count if( $the_query->have_posts() ): ?> <h1>Partners<h1><hr> <?php while( $the_query->have_posts() ) : $the_query->the_post(); if($the_query->post_count=1){ // ... Otherwise it looks like it should work though I am not in a position to ...


0

Also you can customize for pending and drafts or any selected status $args = array( 'post_type' => 'post', 'orderby' => 'title', 'order' => 'ASC', 'post_status' => array( 'pending', 'draft', 'future' ), 'posts_per_page' => 10, );


0

To get the attached term IDs, use get_the_terms() and wp_list_pluck(): if ( $terms = get_the_terms( $post, 'director' ) ) { $term_ids = wp_list_pluck( $terms, 'term_id' ); }


0

Data Insertion It's actually that easy, please follow the following procedures using wp_insert_post(): (Please note that, I assumed you've already registered a Custom Post Type called cars to store car information) <?php //checking whether the form is submitted and the nonce is verified if( isset( $_POST['x_submit'] ) && isset( ...


0

There is no post_name argument for WP_Query, if you're querying by slug, it's just name. Without that argument, your query just gets the latest post back.


0

In your loop, you can use a variable to check, in this case $i, so the code will belong to: <?php $the_query = new WP_Query( 'showposts=7&cat=113' ); ?> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <strong><a href="<?php the_permalink() ?>"><?php the_title(); ...


2

You can still use get_posts: $parents = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'my_custom_post_type', 'fields' => 'ids', // Just get IDs, not objects 'tax_query' => array( array( 'taxonomy' => 'my_custom_tax', 'field' => ...


0

I think, the problem is that you just put filtered query in $query variable but did not set it in the main query i.e. $query->set() See if this works in your code - $query->set( 'tax_query', $taxquery ); instead of $query = new WP_Query( $taxquery );


0

There is a dedicated method for it WP_Query->set_404(). From quick search through code it can be set in WP_Query->parse_query() or WP->handle_404() (note WP, not WP_Query!). But it can (and sometimes does) get set on query externally, for example by plugin that needs to invalidate specific resource.


0

I've needed to do exactly this for a plugin I'm working on and found a slightly different solution based on what Ogier did (which pointed me in the right direction thanks!) With the code provided by Ogier I found that the selected images were not appearing on top even with the extra comparitor code, so after a bit of digging around in the core and ...


0

Use the Co-Authors Plus to assign the authors and the post will show automatically on both author pages. I've used it and works pretty well.


0

You can use the template functions given by Co-Authors Plus plugin such as, coauthors_posts_links() - Co-Authors Plus equivalent of the_author_posts_link() template tag. coauthors() - Co-Authors Plus equivalent of the_author() template tag. Please refer to their documentation


0

By using those named GET variables such as year or monthnum you effectively short circuit the URL rewrite (if you are using pretty permalinks). This way you end up querying the main WP_Query instance first and effectively making yours completely useless (well, you do alter the posts_per_page attribute so there's that). Anyway, the point is that there is a ...


0

Maybe you can try with get_posts() and foreach loop for the second query instead of WP_Query and then you will have something like this: <?php $secondary_query = get_posts('category_name=students'); foreach($secondary_query as $secondary_post): echo "<li>" . get_the_title($secondary_post->ID) . "</li>"; endforeach; ?> With above ...


0

Use meta_query argument in the array. $custom_post_type = 'event'; $args = array( 'post_type' => $custom_post_type, 'post_status' => 'publish', 'meta_key' => 'event_date_and_time', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'posts_per_page' => -1 'meta_query' => array( array( 'key' ...


0

You can use meta_query, if you date information is saved in custom field. Like this: $args = array( 'post_type' => $custom_post_type, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'event_date_and_time', 'value' => current_time('Ymd'), 'compare' => '>=' ) ...


1

Use the save_post hook. Try something like: function jude_classified_activity_entry( $post_id, $post, $update ) { $slug = 'classified'; if ( $slug != $post->post_type ) return; bp_activity_add( // etc ); } add_action( 'save_post', 'jude_classified_activity_entry', 15, 3 );


0

try to use a new WP_Query, when you use get_posts you're using the main WP_Query this has hooks that other plugins can use to alter the query. something else i saw is that you're using include key which is not valid $my_query = new WP_Query( array( 'post__in' => array( 1633, 1634, 1635 ), 'post_status' => 'any', 'post_type' => ...


0

You mentioned you are using a custom taxonomy - therefore including the cat key in your wp_query args won't work. wp_query expects that to be the ID of a term belonging to the standard WP category taxonomy. With a custom tax you need to use the dedicated taxonomy parameters. So your args should be something like: $post_args = array( 'post_type' => ...


0

Ok, found the issue. By analizing the generated query, I realized that it rightly searched for current language posts. I'm currently use polylang as the multilingual plugin, and it correctly associate posts with a 'language' taxonomy. Now, I had far more 10 project posts but only 10 where of the current language. All fine now.


1

The problem is that you can't use the value for the LIKE comparison as you've mentioned. The generated SQL will look something along the lines of: AND CAST(wp_usermeta.meta_value AS CHAR) LIKE '%B%' which means that the query is set to look for every occurrence of letter B in our case. Of course this is not what you want, what you would need is something ...


1

Order by the last word in the post title To order by the speaker's last name, you can use the following setup (PHP 5.4+): // args $args = [ 'posts_per_page' => 10, 'post_type' => 'speaker', 'meta_key' => 'speaker-front-page', 'meta_value' => '1', 'orderby' => 'wpse_last_word', ...


0

The syntax is not 'post-type' or 'post-status', it is with an underscore instead of a dash: 'post_type' => 'testimonials', 'post_status' => 'publish',


0

You need to place the following before your two types to join them: 'meta_query' => array( 'relation' => 'AND' so you'll have: $args = array( 'meta_query' => array( 'relation' => 'AND' array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => '_featured', ...


1

Couple of issues are seen here - You have hooked a function in a template file whereas such code should go in functions.php instead or you can directly put the code of this function in the template. You does not seem to be getting value of $post inside this function. Both the return statements should be removed and just echo $html; should be placed just ...


0

https://codex.wordpress.org/Function_Reference/count_user_posts <?php $user_post_count = count_user_posts( $userid , $post_type ); ?>


1

Are you actually using 'after' => date('Y-m-d h:i',time()) in your code? That will always ask for posts older newer that the exact current time when that query is run. Something like this: 'after' => date( 'Y-m-d h:i', time() - 60 * 60 * 24 ) would give you a reference for 24 hours in the past. The above part is for history's sake. The solution in ...


0

I found a way around this one. Couldn't make sense of the core trac and it still hasn't been patched even though it's a 4 year old ticket. Here is the code I went with for inserting a custom post. The include_once directive is important here. I should also note that the wp_set_auth_cookie(1) sets access rights for this script to the administrator. If you ...


0

query_posts is a PHP function, not a javascript function, it's executed on the server, and the resulting output is sent to the browser. By the time the browser gets the chance to run your if( $(window).width() < 2000 ) { check, it's already too late. The server has finished its PHP script, sent it across, and moved on to new requests. There's also no way ...


0

You are using default category for custom post type. You can instead use a taxonomy query to get filtered result based upon your custom taxonomy terms. Try this - $cat_ids = array(); $postID = get_the_ID(); $categories = get_the_terms($postID, 'custom_taxonomy_name'); //this will give all the terms foreach($categories as $cat) { $cat_ids[] = ...


-1

What about this ? $query_withMeta_search = new WP_Query( array( "post_type" => "product", "s" => $search_query, "meta_query" => array( "key" => "_sku", "value" => $search_query, "compare" => "LIKE" ) ) );


0

I solved it: Just in case anybody ever has any trouble querying a post with the same term of a Taxonomy in another Post Type. I'll post my answer below because I finally solved it on my own. <?php $terms = get_the_terms( $post->ID, 'supplier-tax'); foreach ( $terms as $term ) { $termID[] = $term->term_id; } $the_query = new WP_Query( array( ...


1

Make sure your level ids are 1, 2, and 3, etc. //For check level id 1. if(pmpro_hasMembershipLevel(1, $user->ID)) You can check for get membership level of any user from documentation. PMPro includes a built-in function allowing you to require membership or require a specific membership level.


0

Did you try including wp-load.php instead of wp-blog-header.php? wp-load.php will load the full WP environment, and set up $wpdb, which you would need before using WP_Query. Just a thought. Otherwise, you can also look at wp-cron.php (if you have not done so yet), and see what it does.


0

This part require('./wp-blog-header.php'); is all kinds of bad idea. And if your file is indeed in plugin folder then header isn't even in that location. Custom loads of WordPress core are brittle and the technique is typically only justifiable for performance reasons. It would be better to structure your endpoint via creating actual rewrite endpoint, or ...


2

Yes, custom SQL queries are in essence faster than a custom instance of WP_Query. The disadvantage of a custom SQL query is that you are loosing a lot, like object cache, filters and actions, etc, etc, and it is also discouraged to use custom SQL if Wordpress already offers that specific functionality. WP_Query does have the option however to only query ...


1

From what u have written so far it seems menu_categorie is the custom taxonomy. Make sure it is this only. I get a feeling that you have misses "s" from the end of menu_categorie Anyways The argument 'cat' => $id you were using is used for default taxonomy i.e category. But in your case you have custom taxonomy menu_categorie. So you need to use ...


2

Yes, totally possible. SCENARIO 1 If you need only one taxonomy, all you need to do is to get all the term ID's of all terms assigned to the taxonomy and then pass that array of term ID's to a tax_query (Requires PHP5.4+) $term_ids = get_terms( 'TAXONOMY_NAME', [ // Array of arguments, see get_terms() 'fields' => 'ids' // Get only ...


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


2

You can achive this using WP Query with meta_query argument as following. $args = array ( 'post_type' => array( 'post' ), // YOUR POST TYPE 'meta_query' => array( array( 'key' => 'country', 'value' => $your_country, // THE COUNTRY TO SEARCH 'compare' ...


1

I think we can try the following: (NOTE: This is untested but should in theory work, but remember, it is untested and can be buggy) add_action('pre_get_posts', 'ad_custom_query'); function ad_custom_query($query) { // No other checks should be necessary if ( $query->get( 'custom_query' ) === 1 ) ) { // set the number of posts per page ...


1

Instead of creating a function I just edited the loop with the custom query. My example is for just one post to show. I just used if statement if one or more sticky just show the first sticky. <?php $sticky_posts = get_option( 'sticky_posts' ); $sticky_count = count($sticky_posts); if($sticky_count >= 1) { $loop = new WP_Query('p=' . ...


0

Have you tried wp_get_post_terms() Example usage: $term_lists = wp_get_post_terms($post_id, 'product_tag', array("fields" => "names")); I modified your code and got this to work on my site: <ul id="relatedlist"> <?php $tags = wp_get_post_terms($post_id, 'product_tag'); if ( $tags ) { $tag_ids = array(); ...



Top 50 recent answers are included