Instantly share code, notes, and snippets.

View custom_post_query_with_pagination.php
<?php
global $wp_query;
global $paged;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts='.get_option('posts_per_page').'&post_type=t-shirts'.'&paged='.$paged);
View related_posts_query_by_tag.php
View get_post_types_array.php
<?php
// Get post types
function skima_post_types() {
$post_types = get_post_types([], 'objects');
$posts = array();
foreach ($post_types as $post_type) {
$posts[$post_type->name] = $post_type->labels->singular_name;
}
return $posts;
}
View get_user_role.php
<?php
function prefix_user_role() {
$user_meta = get_userdata(get_the_author_meta( 'ID' ));
$user_roles = $user_meta->roles; //array of roles the user is part of.
echo !empty($user_roles[0]) ? $user_roles[0] : '';
}
View post_titles_array.php
<?php
// query for your post type
$products = new WP_Query(
array (
'post_type' => 'product',
'posts_per_page' => -1
)
);
// we need the array of posts
$posts_array = $products->posts;
View icon-class-to-icon-name-array.php
<?php
function chaoz_icon_array($k) {
$v = array();
foreach ($k as $kv) {
$kv = str_replace('-', ' ', $kv);
$kv = str_replace('icon', '', $kv);
$v[] = array_push($v, ucwords($kv));
}
foreach($v as $key => $value) if($key&1) unset($v[$key]);
return array_combine($k, $v);
View wc_featured_prodcuts_query.php
View cf7_remove_autop.php
<?php
// Remove auto p from Contact Form 7 shortcode output
add_filter('wpcf7_autop_or_not', 'wpcf7_autop_return_false');
function wpcf7_autop_return_false() {
return false;
}
View custom_post.php
<?php
// event.pt.php
/**
* Use namespace to avoid conflict
*/
namespace PostType;
/**
* Class Portfolio
View social_networks_share_urls.php
<?php
function chaoz_social_share() { ?>
<a href="https://facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"><i class="social_facebook"></i></a>
<a href="https://twitter.com/intent/tweet?text=<?php the_permalink(); ?>"><i class="social_twitter"></i></a>
<a href="https://www.pinterest.com/pin/create/button/?url=<?php the_permalink() ?>"><i class="social_pinterest"></i></a>
<a href="https://plus.google.com/share?url=<?php the_permalink() ?>"><i class="social_google_plus"></i></a>
<a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink() ?>"><i class="social_linkedin"></i></a>
<?php
}