aralmac123
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: SrcSet link still pointing to internal address@sterndata I believe srcsets are assigned on the fly or “generated by wordpress” as i’ve read.
Would this just take the internal address then that is possibly stored in the database?
Forum: Fixing WordPress
In reply to: SrcSet link still pointing to internal addressHi @sterndata ,
Thanks for the reply.
So we have a different address for internal and external.
We would only want the srcset to change when it is accessed through the external address.Would using that plugin not change the internal address also?
Forum: Plugins
In reply to: [Unique Headers] Incorrect srcset image urlsHi @ryanhellyer ,
My work is making their wordpress site external and have an external address.
However, the image srcset’s are not translating and are still pointing to the internal address even though the src is set to the external one.Is there a way to fix this that the srcset is pointing to the external one?
Howe is the srcset generated?Thanks
Forum: Developing with WordPress
In reply to: How to Declare a function in functions.phpThanks for replies everyone! @joyously, I think you may be right, I have used a function called “Sites()” in a code snippet in a different part of my site, I am thinking this would then not like this to be called the same name in functions.php.
Forum: Developing with WordPress
In reply to: Intranet breaking with Custom SQL code@bcworkz – I’ve finally cracked it! Here is my code for anyone else struggling with this:
function wpb_search_filter($query) { global $current_user; global $current_user_Location; $current_user = wp_get_current_user(); $current_user_Location=get_metadata( 'user', $current_user->ID, 'mo_ldap_local_custom_attribute_l', true ); global $wpdb; global $sqlquery; global $strSite1; global $strSite2; global $strSite3; if ($query->is_search) { if ($current_user_Location == 'CR'){ $strSite1 = 'Craigavon'; $strSite2 = 'All'; $strSite3 = 'UK'; } $sqlquery = "SELECT DISTINCT wp_posts.id FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id AND wp_terms.name IN ('{$strSite1}', '{$strSite2}', '{$strSite3}') UNION ALL SELECT DISTINCT posts.id FROM wp_posts posts WHERE NOT EXISTS( SELECT * FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE posts.id = wp_posts.id AND wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id) AND posts.post_type IN ('wpfd_file', 'page', 'post') AND posts.post_status NOT IN ('auto-draft', 'trash')"; $postIds = array(); $idArray = array(); $postIds = $wpdb->get_results($sqlquery); foreach ($postIds as $details) { array_push($idArray, $details->id . ","); } if ($current_user_Location == 'CR'){ $query->set('post__in', $idArray); } } return $query; } add_filter('pre_get_posts','wpb_search_filter');
@bcworkz – Thank you for all your guidance, been excellent help!! ??
and i’m sure you will come across some of my questions in the future lol- This reply was modified 4 years, 10 months ago by aralmac123.
Forum: Developing with WordPress
In reply to: Intranet breaking with Custom SQL code@bcworkz , my bad its supposed to be
"Post__in",
you see when we do theget_results
from the query it wasn’t comma separated and that’s why we had to add that into the echo, do you think our$postIds
array will consist of them all as one long string e.g.array('983574845475845863296373834')
or will it be smart enough to comma separate these based on the Ids?Forum: Developing with WordPress
In reply to: Intranet breaking with Custom SQL codeHi @bcworkz @jogesh_pi ,
Taking your advice I’ve updated my code to this:add_action('pre_get_posts','wpb_search_filter'); function wpb_search_filter($query) { global $current_user; global $current_user_Location; $current_user = wp_get_current_user(); $current_user_Location=get_metadata( 'user', $current_user->ID, 'mo_ldap_local_custom_attribute_l', true ); global $wpdb; global $sqlquery; global $strSite1; global $strSite2; global $strSite3; if ($query->is_search) { if ($current_user_Location == 'CR'){ $strSite1 = 'Craigavon'; $strSite2 = 'All'; $strSite3 = 'UK'; } $sqlquery = "SELECT DISTINCT wp_posts.id FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id AND wp_terms.name IN ('{$strSite1}', '{$strSite2}', '{$strSite3}') UNION ALL SELECT DISTINCT posts.id FROM wp_posts posts WHERE NOT EXISTS( SELECT * FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE posts.id = wp_posts.id AND wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id) AND posts.post_type IN ('wpfd_file', 'page', 'post') AND posts.post_status NOT IN ('auto-draft', 'trash')"; $postIds = array(); $postIds = $wpdb->get_results($sqlquery); foreach ($postIds as $details) { echo $details->id . ","; } if ($current_user_Location == 'CR'){ echo "<Br>"; echo "you have reached this point and it is a search!"; $query->set('posts__in', $query); } } return $query; }
I’ve also tried it this way:
if ($current_user_Location == 'CR'){ echo "<Br>"; echo "you have reached this point and it is a search!"; echo "<Br>"; echo "Query has been set!"; $query = new WP_Query(array( 'post__in' => $postIds ));
(I am displaying all of my echos, which are displaying a list of comma separated Ids so I am getting to the point of setting the queries, so I only want to display posts/pages that IDs exist in that array, if doesn’t exist – don’t show)
Both having no luck as it seems just to be displaying all posts and pages and still not applying the filter. Am I still making errors?Really appreciate this help by the way, would be lost without it
- This reply was modified 4 years, 10 months ago by aralmac123.
Forum: Developing with WordPress
In reply to: wpb_search_query filtering by tagsHi @bcworkz,
So ive made a lot of progress with the fact that it now works and my sql is returning the post ids of the posts/pages i want to display.The problem I am having now is that although I have an array with these IDs in it – it does not seem to be applying it to the filter when the user searches?
I have added my updated code for below. Is my code around the “return $query” correct? or how do I actually apply the results from my sql to the filtering process.
Id really appreciate the help ??
function wpb_search_filter($query) { global $current_user; global $current_user_Location; $current_user = wp_get_current_user(); $current_user_Location=get_metadata( 'user', $current_user->ID, 'mo_ldap_local_custom_attribute_l', true ); global $wpdb; global $sqlquery; global $strSite1; global $strSite2; global $strSite3; if ($query->is_search) { if ($current_user_Location == 'CR'){ $strSite1 = 'Craigavon'; $strSite2 = 'All'; $strSite3 = 'UK'; } $sqlquery = "SELECT DISTINCT wp_posts.id FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id AND wp_terms.name IN ('{$strSite1}', '{$strSite2}', '{$strSite3}') UNION ALL SELECT DISTINCT posts.id FROM wp_posts posts WHERE NOT EXISTS( SELECT * FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE posts.id = wp_posts.id AND wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id) AND posts.post_type IN ('wpfd_file', 'page', 'post') AND posts.post_status NOT IN ('auto-draft', 'trash')"; echo $strSite1; echo "<br>"; echo $strSite2; echo "<br>"; echo $strSite3; echo "<br>"; echo $sqlquery; echo "<br>"; $query = array(); $query = $wpdb->get_results($sqlquery); foreach ($query as $details) { echo $details->id . ","; } } return $query; } add_filter('pre_get_posts','wpb_search_filter');
Forum: Developing with WordPress
In reply to: Intranet breaking with Custom SQL codeHi @jogesh_pi !
So ive made a lot of progress with the fact that it now works and my sql is returning the post ids of the posts/pages i want to display.The problem I am having now is that although I have an array with these IDs in it – it does not seem to be applying it to the filter when the user searches?
I have added my updated code for below. Is my code around the “return $query” correct? or how do I actually apply the results from my sql to the filtering process.
Id really appreciate the help ??
function wpb_search_filter($query) { global $current_user; global $current_user_Location; $current_user = wp_get_current_user(); $current_user_Location=get_metadata( 'user', $current_user->ID, 'mo_ldap_local_custom_attribute_l', true ); global $wpdb; global $sqlquery; global $strSite1; global $strSite2; global $strSite3; if ($query->is_search) { if ($current_user_Location == 'CR'){ $strSite1 = 'Craigavon'; $strSite2 = 'All'; $strSite3 = 'UK'; } $sqlquery = "SELECT DISTINCT wp_posts.id FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id AND wp_terms.name IN ('{$strSite1}', '{$strSite2}', '{$strSite3}') UNION ALL SELECT DISTINCT posts.id FROM wp_posts posts WHERE NOT EXISTS( SELECT * FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE posts.id = wp_posts.id AND wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id) AND posts.post_type IN ('wpfd_file', 'page', 'post') AND posts.post_status NOT IN ('auto-draft', 'trash')"; echo $strSite1; echo "<br>"; echo $strSite2; echo "<br>"; echo $strSite3; echo "<br>"; echo $sqlquery; echo "<br>"; $query = array(); $query = $wpdb->get_results($sqlquery); foreach ($query as $details) { echo $details->id . ","; } } return $query; } add_filter('pre_get_posts','wpb_search_filter');
- This reply was modified 4 years, 10 months ago by aralmac123.
- This reply was modified 4 years, 10 months ago by aralmac123.
Forum: Developing with WordPress
In reply to: Intranet breaking with Custom SQL code@jogesh_pi ive updated my code in the post to match what you have shown me, I also ran the SQL statements into PhpMyAdmin and they are definitely correct and working.
Site is still breaking ??
Forum: Developing with WordPress
In reply to: Intranet breaking with Custom SQL code@jogesh_pi thanks for the reply! see in terms of my return statement at the end – what is the correct way for me to set the query returned equal to my sql statement?
Is it $query = $wpdb->get_results($sqlquery)?
Thanks for the tip about stating the variables also!
Forum: Developing with WordPress
In reply to: wpb_search_query filtering by tagsThanks for the reply! @bcworkz – I am very limited with wordpress and php experience and this is a big blocker for our site. So you don’t believe working with wp_query will work with displaying posts with no tag? With regards to the SQL – can this be written in functions.php or where is this developed?
Hi @champsupertramp ,
How would we get what the user has entered into the search bar in order to use it in the wp_query?Hi @champsupertramp ,
thanks for your reply!Our version is 2.1.2.
I believe that we can filter by a custom field but what we are trying to achieve is that the user can actually search by that custom field.
In our case it is by number plate. So, I can enter my number plate, click search and it will return my user profile that is associated with that number plate.Can this be achieved?
Also, the code we have shown you above was give to us by UM, however, search results only return when searched by first name and surname. Should it not work when we search for other meta such as department etc based on the code they give us?
Thanks in advance for any help ??
@champsupertramp okay but can you select multiple options for the parent drop down?
for example, say it was checkboxes, i would like to check a few destinations and then in the 2nd drop down list it is populated with the checkboxes that are selected.
I dont think checkboxes can use callback so i thought it may be possible with multi-select?