yy
This file contains 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
// hooking script for custom post type 'homework' | |
add_action( 'admin_print_scripts-post-new.php', 'homework_admin_script', 11 ); | |
add_action( 'admin_print_scripts-post.php', 'homework_admin_script', 11 ); | |
function homework_admin_script() { | |
global $post_type; | |
if( 'homework' == $post_type ) | |
wp_enqueue_script( 'homework-admin-script', get_bloginfo('template_directory') . '/js/admin_homework.js' ); | |
} |
This file contains 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_product_to_cart($product_id, $quantity, $variation_id, $variation, $cart_item_data); | |
function add_product_to_cart($product_id, $default_product_quantity, $variation_id, $variation = array(), $cart_item_data = array()) { | |
//check if product already in cart | |
if (sizeof(WC()->cart->get_cart()) > 0) { | |
WC()->session->set("cart_strorage", WC()->cart->get_cart()); | |
foreach (WC()->cart->get_cart() as $cart_item_key => $values) { | |
$_product = $values['data']; | |
if ($_product->id == $product_id) { | |
$found = true; |
This file contains 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
attach_the_terms_to_a_post($post_id, $taxanomy_name, $combine_term_ids); | |
function attach_the_terms_to_a_post($post_id, $taxanomy_name, $combine_term_ids) { | |
$combine_term_ids = array_map('intval', $combine_term_ids); | |
$result = wp_set_object_terms($post_id, $combine_term_ids, $taxanomy_name); | |
return $result; | |
} |
This file contains 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
/* | |
* This function checks if a post is inserted in the wp database based on a metakey and a metavalue, and return its postid if it is present | |
* $is_meta_value_unique contains true or false. if true is passed then one postid is returned else array of postids is returned | |
*/ | |
check_if_a_post_is_inserted($meta_key_name, $meta_key_value, $posttype, $is_meta_value_unique); | |
function check_if_a_post_is_inserted($meta_key_name, $meta_key_value, $posttype, $is_meta_value_unique) { | |
if ($is_meta_value_unique) { | |
$posts_per_page = 1; |
This file contains 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
/* | |
* This function converts meta of a post into the term | |
*/ | |
convert_metato_term($posttype, $taxanomy_name, $meta_key_name); | |
function convert_metato_term($posttype, $taxanomy_name, $meta_key_name) { | |
global $post; | |
$args = array( | |
'post_type' => $posttype, | |
'post_status' => 'publish', |
This file contains 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
/* | |
* Deletes all the posts of a posttype | |
*/ | |
delete_all_posts_of_a_postype($posttype, $posts_per_page); | |
function delete_all_events() { | |
global $post; | |
$args = array( | |
'post_type' => $posttype, | |
'post_status' => 'publish', |
This file contains 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
/* | |
* Delete a metakey and its value from wordpress db based on comparison operator | |
* $comparison_operator can contain 'Like' or '=' | |
*/ | |
delete_metakey($metakey_to_delete, $comparison_operator); | |
function delete_metakey($metakey_to_delete, $comparison_operator) { | |
global $wpdb; | |
if ($comparison_operator == 'LIKE') { | |
$mysql_query = "DELETE FROM $wpdb->postmeta WHERE meta_key " . $comparison_operator . " '%" . $metakey_to_delete . "%'"; |
This file contains 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
/* | |
* This function returns the post count views of a posttype | |
*/ | |
getPostViews($postID); | |
function getPostViews($postID) { | |
$count_key = 'post_views_count'; | |
$count = get_post_meta($postID, $count_key, true); | |
if ($count == '') { | |
delete_post_meta($postID, $count_key); |
NewerOlder