This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| global $sitepress; | |
| $trid = $sitepress->get_element_trid($post_id); | |
| if($trid){ | |
| $translations = $sitepress->get_element_translations($trid); | |
| // Unset current language | |
| unset($translations[ICL_LANGUAGE_CODE]); | |
| foreach($translations as $translation){ | |
| echo get_post_meta($translation->element_id, 'my_field', true); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function disable_search( $query, $error = true ) { | |
| if ( is_search() ) { | |
| $query->is_search = false; | |
| $query->query_vars[s] = false; | |
| $query->query[s] = false; | |
| // to error | |
| if ( $error == true ) | |
| $query->is_404 = true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h3>All Post Meta</h3> | |
| <?php $getPostCustom=get_post_custom(); // Get all the data ?> | |
| <?php | |
| foreach($getPostCustom as $name=>$value) { | |
| echo "<strong>".$name."</strong>"." => "; | |
| foreach($value as $nameAr=>$valueAr) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function _fix_child_css_version( $src ) { | |
| $parts = explode( '?', $src ); | |
| if ( stristr( $parts[0], '-child/style.css' ) ) { | |
| $child_ver = filemtime( get_stylesheet_directory() . '/style.css' ); | |
| return $parts[0] . '?v=' . $child_ver; | |
| } | |
| else { | |
| return $src; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // wp_get_object_terms() always queries the database | |
| /* If you’re looping over WP_Query results, you should prefer get_the_terms() instead. | |
| It’s pretty much the same for most use cases, but it uses the object cache, | |
| which by default gets populated with the terms for the posts matching your query — unless you specifically | |
| set update_post_term_cache as false when instantiating WP_Query. | |
| */ | |
| // Get terms for post | |
| if ( ! function_exists( 'storefront_post_terms' ) ) { | |
| function storefront_post_terms(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); | |
| function display_price_in_variation_option_name( $term ) { | |
| global $wpdb, $product; | |
| if ( empty( $term ) ) return $term; | |
| if ( empty( $product->id ) ) return $term; | |
| $id = $product->get_id(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Recursively sort an array of taxonomy terms hierarchically. Child categories will be | |
| * placed under a 'children' member of their parent term. | |
| * @param Array $cats taxonomy term objects to sort | |
| * @param integer $parentId the current parent ID to put them in | |
| */ | |
| function sort_terms_hierarchicaly(Array $cats, $parentId = 0) | |
| { | |
| $into = []; | |
| foreach ($cats as $i => $cat) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action('add_attachment', function($postId) { | |
| // get the attachment post object | |
| $attachment = get_post($postId); | |
| // get the slug for the attachment | |
| $slug = $attachment->post_name; | |
| // update the post data of the attachment with an edited slug | |
| wp_update_post(array( | |
| 'ID' => $postId, | |
| 'post_name' => 'media-'.$slug, //adds a prefix | |
| //'post_name' => $slug.'-photo', //adds a suffix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getLastPathSegment($url) { | |
| $path = parse_url($url, PHP_URL_PATH); // to get the path from a whole URL | |
| $pathTrimmed = trim($path, '/'); // normalise with no leading or trailing slash | |
| $pathTokens = explode('/', $pathTrimmed); // get segments delimited by a slash | |
| if (substr($path, -1) !== '/') { | |
| array_pop($pathTokens); | |
| } | |
| return end($pathTokens); // get the last segment | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (is_admin()){ | |
| if ( !get_option('db_last_auto_cnl') || (get_option('db_last_auto_cnl') < time()- 86400) ) { | |
| global $wpdb; | |
| $del= $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'"); | |
| $del= $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'"); | |
| $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_rss%'"); | |
| $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_rss_%'"); | |
| $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_feed_%'"); | |
| $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_feed_%'"); | |
| //if you want, you can uncomment these too |