Bobozar
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Get Custom Field Value With URL ParameterI inserted the below query code in the functions.php function
global $wp_query; echo $wp_query->request;And the SQL output goes like this.
SELECT wpxx_posts.* FROM wpxx_posts WHERE 1=1 AND wpxx_posts.ID = 2647 AND wpxx_posts.post_type = 'page' ORDER BY wpxx_posts.post_date DESC SELECT wpxx_posts.* FROM wpxx_posts WHERE 1=1 AND wpxx_posts.ID = 2647 AND wpxx_posts.post_type = 'page' ORDER BY wpxx_posts.post_date DESC SELECT wpxx_posts.* FROM wpxx_posts WHERE 1=1 AND wpxx_posts.ID = 2647 AND wpxx_posts.post_type = 'page' ORDER BY wpxx_posts.post_date DESC SELECT wpxx_posts.* FROM wpxx_posts WHERE 1=1 AND wpxx_posts.ID = 2647 AND wpxx_posts.post_type = 'page' ORDER BY wpxx_posts.post_date DESC SELECT wpxx_posts.* FROM wpxx_posts WHERE 1=1 AND wpxx_posts.ID = 2647 AND wpxx_posts.post_type = 'page' ORDER BY wpxx_posts.post_date DESC SELECT wpxx_posts.* FROM wpxx_posts WHERE 1=1 AND wpxx_posts.ID = 2647 AND wpxx_posts.post_type = 'page' ORDER BY wpxx_posts.post_date DESCThe function is:
function my_pre_get_posts( $query ) { // do not modify queries in the admin if( is_admin() ) { return $query; } // only modify queries for 'event' post type //if( isset($query->query_vars['post_type'] && $query->query_vars['post_type'] == 'post')) {# if( isset( $query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post') { // allow the url to alter the query if( isset($_GET['country']) ) { $query->set('meta_key', 'country'); $query->set('meta_value', $_GET['country']); } } global $wp_query; echo $wp_query->request; // return return $query; } add_action('pre_get_posts', 'my_pre_get_posts');- This reply was modified 8 years, 9 months ago by Bobozar.
Forum: Developing with WordPress
In reply to: Get Custom Field Value With URL ParameterWhen I adjusted the code and inserted dnyanraja’s meta_query alternative, I got the below error:
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\wamp64\www\\wp-content\themes\look\functions.php on line 20Line 20 reads:
$query->set('meta_query' => array(Main code:
function my_pre_get_posts( $query ) { // do not modify queries in the admin if( is_admin() ) { return $query; } // only modify queries for 'event' post type //if( isset($query->query_vars['post_type'] && $query->query_vars['post_type'] == 'post')) {# if( isset( $query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post') { // allow the url to alter the query if( isset($_GET['country']) ) { $query->set('meta_query' => array( 'key' => 'country', 'value' => $_GET[‘country’], 'compare' => 'LIKE' ) ) } } // return return $query; } add_action('pre_get_posts', 'my_pre_get_posts');But when I changed it to the below code
function my_pre_get_posts( $query ) { // do not modify queries in the admin if( is_admin() ) { return $query; } // only modify queries for 'event' post type //if( isset($query->query_vars['post_type'] && $query->query_vars['post_type'] == 'post')) {# if( isset( $query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post') { // allow the url to alter the query if( isset($_GET['country']) ) { $query->set('meta_key', 'country'); $query->set('meta_value', $_GET['country']); } } // return return $query; } add_action('pre_get_posts', 'my_pre_get_posts');And I visited the url example.com/?country=us
I got ‘Sorry, Posts you requested could not be found…’
With this I guess it is not filtering the field.
Forum: Developing with WordPress
In reply to: Get Custom Field Value With URL ParameterAfter trying dnyanraja’s answer, I got the error below:
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in C:\wamp64\www\\wp-content\themes\look\functions.php on line 14On line 14, I have the below code:
if( isset($query->query_vars['post_type'] && $query->query_vars['post_type'] == 'post')) {Forum: Developing with WordPress
In reply to: Get Custom Field Value With URL ParameterThanks for your input. Can you help with a code solution. I’m not a PHP developer so I don’t know how to go about writing the code.
Have you solved the problem?
It would be nice if those features can be added on time. Thanks so much!!
Hello, I followed your steps. Even before that, I deactivated Jetpack and activate it back again. Yet no luck.
I deleted Jetpack through FTP and download and put it back manually and connect to wordpress with another account, yet no luck!
Don’t know what to do again.
F12 is not poping up anything, so I can’t check any lines. I’ve sent you a mail. Kindly check it out.
Yeah. I’m suing Smart mag theme http://themeforest.net/item/smartmag-responsive-retina-wordpress-magazine/6652608. In my local server, I can see the button, but on my online server, I can’t find it.
Forum: Your WordPress
In reply to: Help a newbie out!Hey bro tanx let me try it nd incase i dnt get it plz gimme ur contact so dat we cn chat thanks