pdg87
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] Shipping Options based on postcode not showing for some usersHi, thanks for the reply, I will get the info to you, but I think if you were to test it, it will work. It has worked eveyrtime I test it, I think its an edge case. I think the zones work okay, it is more the ajax failing to check the postcode I think, what triggers the check? any address field change? I’m wondering if I could force the check more often, specifically on keyup on postcode field for example
Forum: Fixing WordPress
In reply to: Inserted character on my pagesYou have an extra ‘<‘ tag after <body> tag.
If you open you header.php file you should be able to see it and delete it.
Forum: Fixing WordPress
In reply to: Site Structure and dynamic pagesHi Chad,
I finally got around to trying this out. This is a better example of what I am trying to acheive:
https://wordpress.stackexchange.com/questions/191878/how-can-i-achieve-this-site-url-structure
I couldntreally get the above working. So I am currently trying to use a custom post type with a custom taxonomy. Custom post type is ‘offers’ with a custom taxonomy ‘stores’. I am getting there but url’s are not behaving quite right.
site.com/offers – loads
site.com/offers/storename/offer-post – loads
site.com/offers/storename – does not load (this should be a list of offers for that store taxonomy)Also, I am using breadcrumbs plugin and the link generated for this:
displays as: site.com/offers/%stores_slug%/storename
Something not quite right with my rewrite rules?
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Ah that’s a shame seems close, maybe I should switch to using just custom fields?
I’m going to carry on for now with some other areas of the website, but will address this again soon and see if I can use custom fields/make do with more simple query.
I may drop you PM in the coming weeks if this blocks me too much. Would be great if you could help out in return for some beer money ?? Thanks again for the help!
FWIW, _store_brands has always been in the db, I noticed it the other day when having a look with the value field_blah (I think this is he unique key for the custom field). What were you trying to do with this value? overwrite it with an array?
Either way hopefully there’s some useful info in here for noobs like myself.
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Thanks for sticking with it, but still the same output.. When you say update, Im just going to a store post which has the acf store_brands and clicking ‘update’ to save it, that’s what you mean? ??
I’m starting to think I should just do away with the alternative_brand_names list and query store_brands as an array value against the single value of brand_name, which seems to work..
Not ideal for my situation, but I could probably work around it as worse case.
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?No thats not a correct value for brand_name. Looking in the db, field_55590c17ac022 is a value for _store_brands.
hmm looks like the data is not getting populated correctly..
Array ( [0] => field_55590c17ac022 )
SELECT wp_postmeta.meta_value FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) WHERE wp_posts.post_type IN ( 'designers', 'stores' ) AND wp_posts.post_status = 'publish' AND wp_posts.ID NOT IN ( 18 ) AND ( wp_postmeta.meta_key = 'alternative_brand_names' AND mt1.meta_key = 'brand_name' AND CAST( mt1.meta_value AS CHAR) IN ( 'field_55590c17ac022' ) ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
Array ( )
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?with the above, it just prints the post titles of all store posts e.g.
Store1
Store2I added a new store (store3) and left the store_brands field blank. This still shows up on the all store posts.
Store1
Store2
store3are shown on every individual store post. (store1, store2, store3)
printing $args gives this:
Array ( [post_type] => Array ( [0] => designers [1] => stores ) [meta_query] => Array ( [relation] => OR [0] => Array ( [relation] => OR [0] => Array ( [key] => brand_name [value] => Array ( [0] => field_55590c17ac022 ) [compare] => IN ) [1] => Array ( [key] => _store_brands [value] => Array ( [0] => field_55590c17ac022 ) [compare] => IN ) ) ) )
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Yeah sorry it’s confusing with similar CF and brand names and my php is terrible. I updated the functions.php file and then resaved a store post with store_brands CF. This is the code I have in single-stores.php (I changed the name of post type from brands to ‘designers’ and custom field name brands_name_alt to ‘alternative_brand_names’ as I had names them wrong in previous posts ??
<?php global $wpdb; $post_id = absint( $post->ID ); $post_types = array( 'designers', 'stores' ); $list = (array) get_post_meta( $post_id, "_store_brands", true ); $array = array_filter( array_map( 'trim', $list ) ); if ( !empty( $array ) && $post_id ) { $post_type_sql = "'" . implode( "', '", array_map( 'esc_sql', $post_types ) ) . "'"; $meta_value_sql = "'" . implode( "', '", array_map( 'esc_sql', $array ) ) . "'"; // First query to get the brands_name_alt meta values $query = "SELECT $wpdb->postmeta.meta_value FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) INNER JOIN $wpdb->postmeta AS mt1 ON ( $wpdb->posts.ID = mt1.post_id ) WHERE $wpdb->posts.post_type IN ( $post_type_sql ) AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.ID NOT IN ( $post_id ) AND ( $wpdb->postmeta.meta_key = 'alternative_brand_names' AND mt1.meta_key = 'brand_name' AND CAST( mt1.meta_value AS CHAR) IN ( $meta_value_sql ) ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC"; $meta_values = $wpdb->get_col( $query ); $args = array( 'post_type' => $post_types, 'meta_query' => array( 'relation' => 'OR', array( 'relation' => 'OR', array( 'key' => 'brand_name', 'value' => $array, 'compare' => 'IN' ), array( 'key' => '_store_brands', 'value' => $array, 'compare' => 'IN' ), ) ), ); // Check if meta values were found for the brands_name_alt key if ( !empty( $meta_values ) ) { // merge all meta values $all_values = array(); foreach ( $meta_values as $value ) { $value = array_filter( array_map( 'trim', (array) explode( ',', $value ) ) ); $all_values = array_merge( $all_values, $value ); } // Query for all posts with the store_brands values in the brands_name_alt values $args['meta_query'][] = array( 'key' => '_store_brands', 'value' => $all_values, 'compare' => 'IN' ); } $custom_query = new WP_Query($args); } while($custom_query->have_posts()) : $custom_query->the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> <?php the_content(); ?> </div> <?php endwhile; ?> <?php wp_reset_postdata(); // reset the query ?>
There is a good chance there is something wrong with what I have added. The above just returns both store posts I have made.
If I move the while statement above the last trailing { the page doesn’t load.
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Wow thanks for that, I was about to give up on it. However I think this will return stores? rather than brands?
the list array (value?) should be made from the csv store_brands from the stores post type.
Then this is checked against brand_name (key?) and brands_name_alt(key?) custom field in the brand post type.
To return a list of brand posts on a store post.
Hopefully just a case of changing some of the field names around?
Forum: Fixing WordPress
In reply to: Unable to remove Featured Image in Post page.Hey, no problem, Its just some margin gettin applied still to the header element.
If you change:
<header class="entry-header">
<header class="entry-header-single">
It should work.
Basically just changing the element class names adding ‘-single’ this way it doesn not pick up any styling from the other page elements and we could style these elements differently if needed.
This wont cause any layout problems. Just if you ever want an post to include the large header image. You would have to set up a custom template for certain posts to acheive this.
These changes will show on every post. So the layout will be like this.
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Ah, thought so Keesie ?? There could be 100+ brands to enter into store_brands for every store so it would take ages to have seperate fields for each brand..
Any other options? Is it achievable using wpdb sql query?
Or someway to break csv entered values into seperate fields?
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?great, I will report back. Thanks for taking your time to help Keesie, Much apprecited!
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Okay thanks looking forward to giving it a try. I’m away from the code now which is annoying.
But in my first example, changing the following params seemed to not work/work.
presuming the value of brand_name_alt is [FordCar, Fored]
[key] => brand_name_alt [value] => Array ( [0] => FordCar [1] => Fored ) [compare] => IN
returned nothing
[key] => brand_name_alt [value] => "FordCar" [compare] => LIKE
Worked, but I need an array as the value so no use.
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?Thanks a lot for the help. I will give that a try as soon as I get home. My php/sql is weak I’m more design/front end.
I want to place brand posts on store posts where there is a match in store_brands and brand_name OR store_brands brands_name_alt.
I still think it will be a problem because its checking array values ($all_values) against a key which contains a string (brands_name_alt) using operator IN so it doesnt find an exact match. This field would have to have a single value? E.g. [Mercedes Benz] rather than: [Mercedes Benz, Mercedes-Benz]
I could very easily be wrong so will give it a try this evening ??
Forum: Fixing WordPress
In reply to: Match values from two arrays to return posts. wp_query?That’s almost correct,
brands_name_alt values will never be the same as brand_name values.
But brand_name_alt could be present in store_brands.
The query works fine with brand_name, because this is always a single value. e.g. [Mercedes] so the ‘IN’ compare works well.
However because brand name alt is a list e.g. [Mercedes-Benz, MercedesBenz] and it doesnt work with that.
store_brands might include [Mercedes] or it might include [Mercedes-Benz] or it might contain [MercedesBenz]