Tag Info

New answers tagged

0

pagename is for the page post type, if you are trying to pass the slug for the presskit post type, remove post_type and pagename and just set presskit=$matches[1] instead.


1

For example if there are 10 custom posts, and No. 1 is the oldest, and they happened to select the 3rd oldest one, they want it to say "No. 3". There is a more elegant way than that function: $args = array( 'post_type' => 'book', 'fields' => 'ids', 'ignore_sticky_posts' => true, 'orderby' => 'post_date', 'order' => 'DESC' ...


4

The function get_the_time is only designed to work either in the main WordPress loop or a custom loop using WP_Query, so the way you are using it won't work correctly. The following is the right way to use it, using a custom WP_Query loop: <?php // Get years that have posts $years = $wpdb->get_results( "SELECT DISTINCT YEAR(post_date) AS year FROM ...


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

wpdb uses PHP's mysqli_affected_rows() or mysql_affected_rows(), which can be disabled via an argument in php.ini. I am guessing that that is what has happened. Check the disabled_functions line in your php.ini file and remove the references to those function. Of the top of my head, I am not sure if extensions like Suhosin mess with that function but that ...


1

as ChrisL said in the comments, you should add order and orderby to your arguments : $args = array( 'post_type' => 'totem', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' );


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

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


0

Try to use $wpdb->prefix insted of $wpdb in Delete query. Eg:- $wpdb->query( 'DELETE FROM '.$wpdb->prefix.'paypal WHERE id = "'.$myid.'"' );


0

You can use wp_signon function Here is an example $creds = array(); $creds['user_login'] = 'example'; $creds['user_password'] = 'plaintextpw'; $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message();


0

INDEX.php file is refined far after the pre_get_posts hook... so, you should define the $popular variable before that hook.


0

I know this may not be the appropriate place to ask - but you all seem to know about this issue and I can't find a resolution anywhere so if someone could help - I would VERY much appreciate it because my site is almost non-responsive in several areas of the admin most importanly in the "new page/post" sections. I've deactivated every plugin and used the ...


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


1

In the case that the start_date custom field only exists for the event post type, this works: $query->set( 'meta_query', array( 'relation' => 'OR', array( 'key' => 'start_date', 'compare' => 'NOT EXISTS', ), array( 'key' => 'start_date', 'value' => $today = date( 'Ymd' ), 'compare' ...


0

the arguments for your query would be like $args = array( 'post_type' => 'articles', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'name', ...


2

Your logic in your code is wrong. Read your code in plain English. If the current post is number 3, show my custom content, else, show the posts as normal. What you want is the following If the current post is number 3, show my custom content. Show all my posts as normal To achieve this, you need only wrap your custom content in your ...


1

For anyone struggling with this. 'orderby'=>'post__in' makes this work. <?php $successful_musics_array = array('1682', '1684', '556', '1793', '558', '1788', '320', '1190', '1865', '1125', '1863', '1540'); $query = new WP_Query( array( 'post_type' => 'songs', 'posts_per_page' => '15', 'post__in' => $successful_musics_array, ...


1

To load admin scripts only on your pages, you should use the $hook-parameter: function enqueue_scripts( $hook ) { if( 'my-page' != $hook ) return; wp_enqueue_script('jquery'); wp_enqueue_media(); // etc... } add_action('admin_enqueue_scripts', 'enqueue_scripts'); Concerning the loading problem. This seems to be still an open problem. The ...


0

An alternate SQL statement from Milo's would be: $querystr = " SELECT {$wpdb->posts}.ID FROM {$wpdb->posts} LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_social_' ) WHERE {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_date < NOW() ...


0

To go off of Johannes' response, since it is a serialized array, if you happen to be storing something like user id's (which was my case), you may need to handle it a little differently. Post meta was being saved like: array( "1", "23", "99"); So yes they are integers but through update_post_meta they were being saved as strings. 'meta_query' => ...


0

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

As @s_ha_dum already pointed out, you can use the build in private posts status function when publishing posts. This will hide these posts from all logged out users. As you have already went down the custom fields route, you can make the following changes to your custom post type archive Remove your custom query. This messes up page functionalities and ...


0

As per this WPSE thread you are actually putting overload to the apache. That's why it's reacting like that. :) So let's cut the overload, use is_main_query() properly, and just add a simple conditional to your pre_get_posts hooked function: function e_exclude_posts( $query ) { if( !is_admin() && $query->is_main_query() && ...


0

I got it ! Here is my final code for people who will search for similar problem :) in functions.php : function se190254_custom_sql_for_search( ) { global $wpdb; //For security escape the search parameter $search_string = esc_sql($_GET['s']); //Build the SQL request with $wpdb->base_prefix for "portability" $sql = "SELECT ...


0

I believe you need to setup the post data for each post. Try: $search_result = search_query_with_trips(); foreach( $search_result as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; You may need global $post before the foreach ...



Top 50 recent answers are included