Tag Info

New answers tagged

0

Make sure that the value portion of the data parameter's column=>value pairs must be scalar. If you pass an array (or object) as a value to be inserted you will generate a warning similar to mysql_real_escape_string() expects parameter 1 to be string, array given on line 880 in file /var/www/html/wp-includes/wp-db.php". Rather then above your code is ...


-2

Here is Wordpress's official article on the topic.


1

Don't forget that when you are adding a filter it will stay there for all subsequent request. I would suggest you remove the closure and do something like this: function x_example( $input ) { remove_filter( 'posts_where', 'x_example' ); return $input; } add_filter( 'posts_where', 'x_example' ); You will have to do the same thing for the posts_join ...


0

use % to set the template(style) or you can use :nth-child(16n+1) ... <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php $st = 16; //after how many blocks you want to repeat the pattern <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count%$st == 1) : ?> <div class="style-1"><?php ...


0

Remove line#5 and do the following: if ($query->have_posts()) : echo '<h2 class="seccion col-sm-12">Tour</h2>'; //we are showing the div inside the conditional I removed unnecessary <div>, as <h2> itself is a block element and can do the trick for you.


0

Try with: $str = get_the_content();


2

You have a couple of issues here the_content() echos the content to screen. You should be using get_the_content() which returns the content. Just remember, get_the_content() is unfiltered, so if you need filtered content, use apply_filters( 'the_content', get_the_content() ) which will return filtered content. Your explode() function is probably wrong as ...


0

Have you check your result-set, what result you are getting in $query obj. another thing, there is no need to use 'relation' => 'OR', in meta query array, have a try with this as well. And instead of 'numberposts' use 'posts_per_page' this will help. :) or you can remove the meta_query and make your $arg something like $args = array( 's' => $keyword, ...


0

In the context of your code the inclusion has no use but, to answer your question in another way, upgrade.php is a file that defines the dbDelta() function, which can be used to upgrade a MySQL table if it allready exists. This mechanism comes in handy when upgrading a plugin to a version that uses different MySQL tables without loss of data. The default ...


1

As already hinted by @Milo, check if you have terms before appending your tax_query You can try the following: (Requires PHP 5.4+ due to short array syntax, revert to old syntax if necessary) $args = [ 'post_type' => 'product', 'posts_per_page' => 15, 'paged' => $paged, 'post__not_in' => $exclude, 's' => $filter, ]; // ...


0

There is a plugin for this. It allows comfortable use of the backend and also replaces the URL in the post-content and some other fields, if you want to: https://wordpress.org/plugins/better-search-replace/


1

I notice that to link to each post, I am calling get_permalink() and this is creating an extra DB query for each post. Not true. If you check the link to the very old trac ticket #18822 in the post that you have linked to, this issue was raised by @kaiser in 2011. The question was answered by @scribu For example: $posts = get_posts(); foreach ( ...


0

One option is to fetch all of the posts to a single array and filter that array 50 ways. This would only generate the one query: $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'school' )); To filter your array you would do something like this: $this_state = "Texas"; $state_posts = array_filter($posts, ...


2

In addition to Milo's answer: In wp::parse_request() the request URI is matched against the rewrite rules stored in $GLOBALS[ 'wp_rewrite' ]->rules. That means, the »route« will be parsed into query variables. The actual matching rule is stored in $GLOBALS[ 'wp_rewrite' ]->matches which is quite helpful for debugging: add_action( 'wp_footer', ...


2

parse_query is where the majority of the work is done. Query vars and is_ conditionals are set, and template-loader.php just checks those is_ conditional tags to load the appropriate template.


2

<?php $args = array( 'posts_per_page' => -1, 'post_type' => 'event', 'meta_query' => array( array( 'key' => 'event_date_end_timestamp', 'value' => time(), 'type' => 'numeric', 'compare' => '<' ) ) ); $programs = new WP_Query($args); ?> ...


1

As you have stated, rank is defined by a value in a custom field, so you would just need to get the value from the custom field and display it. You can try the following inside your loop global $post; // Just make sure the custom field name is correct $rank = get_post_meta( $post->ID, 'custom_field', true ); // Display the title and rank echo 'Rank ' ...


0

if you want to keep the row with the lowest id value: DELETE n1 FROM table n1, table n2 WHERE n1.id > n2.id AND n1.meta_key = n2.meta_key OR if you want to keep the row with the highest id value: DELETE n1 FROM table n1, table n2 WHERE n1.id < n2.id AND n1.meta_key= n2.meta_key


1

Maybe it helps function wpcodex_filter_main_search_post_limits( $limit, $query ) { return 'LIMIT 0, 100'; } add_filter( 'post_limits', 'wpcodex_filter_main_search_post_limits', 10, 2 ); More: post_limits filter


0

Try this code that will helps you display only 10 pages. This is code where you want to display the post: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'property', 'posts_per_page' => 10,'paged'=> $paged,'orderby'=> 'meta_value_num','order'=> 'DESC'); $loop = new WP_Query( $args ); ...


2

Before I start, do not use get_posts for paginated queries. get_posts legally breaks pagination, and does not return the query object. If you need to paginate queries, use WP_Query As for your issue, I really don't think limiting the total overall amount of posts to only 100 is possible when you involve pagination. The only scenarios I can think of is: ...


0

I think do you mean GROUP Post by category/taxonomy NOT SORT. Here, Is a code to GROUP by category/taxonomy $terms = get_terms( 'my_cat_name' ); Here, cat_name name is the name of taxonomy, When you register it like this: e.g. register_taxonomy( 'my_cat_name', array( 'custom_post_name' ), $args ); Use it in Query e.g.: $args = array( ...


0

You can't change the DESC to ASC "within the IF statement". The query has already ran at that point. I don't really understand what the code is meant to do though. I don't really see that code ever producing the pattern you describe. Specifically, I don't understand what the shortcode strings or for or how that is supposed to work. However, I can duplicate ...


0

I think the query we run is maybe limited in some way... So far as I know, your query and the processing you do of the results is going to be limited by server resources-- memory, etc-- not by WordPress other than the WordPress defined PHP memory limit, to some extent. You can try altering that and see if it helps. Otherwise, you will need help from ...


0

Yeah I think it works with limited no of items, I have also find similar issue with wp_query, on my client's site, there are 20,000+ products were there, btw I did resolve this by executing sql query,instead of wp_query. ;)


0

Absolutely. Since you can instantiate to a variable a query you can do it as much times as you want. Of course query loops require a lot of connections to the database so you have to be careful. Very often if you need many subqueries it basically means that your workflow can be enhanced in some way. Example of a subquery: $some_posts = new WP_Query(); ...


1

Try "bootstrapping" WordPress for your custom script first: include '../../../wp-load.php' (you might need to adjust the path for your needs). Then you can safely use the $wpdb class, such as $wpdb->get_results and other goodies. Don't forget to escape/clean your incoming data, if any. WordPress documentation on $wpdb PS: always try to use "builtin" ...



Top 50 recent answers are included