Skip to content

Instantly share code, notes, and snippets.

View mdjwel's full-sized avatar
🎯
Focusing

Eh Jewel mdjwel

🎯
Focusing
View GitHub Profile
@mdjwel
mdjwel / striped_loop.php
Created November 13, 2018 09:53
bootstrap row loop, loop after a specific number of loops, striped loop
<?php
if (!empty($settings['works'])) {
$i = 0;
foreach ( $settings['works'] as $work ) {
++$i;
?>
<div class="col-xs-12 col-sm-6 col-md-5 <?php echo ($i % 2 == 0) ? 'col-md-offset-2' : ''; ?>">
<div class="single-experience">
<div class="date"><?php echo esc_html($work['datetime']) ?></div>
<h4 class="title"><?php echo esc_html($work['title']) ?></h4>
@mdjwel
mdjwel / decimal_number_loop.php
Created November 12, 2018 11:00
Increase loop value by decimal point number
<?php
if (is_array( $faqs )) {
$i = 0.2;
foreach ( $faqs as $faq ) {
?>
<div class="col-xs-12 col-sm-6">
<div class="single-faq wow fadeInUp" data-wow-delay="<?php echo $i ?>s">
<h5 class="title"><?php echo esc_html($faq['title']) ?></h5>
<p> <?php echo wp_kses_post($faq['description']) ?> </p>
</div>
@mdjwel
mdjwel / popular_posts_query.php
Last active September 11, 2021 06:40
WordPress Custom Query Based Condition
@mdjwel
mdjwel / get_post_types_array.php
Created September 8, 2018 19:18
Get post types array with name => singular name
<?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;
}
@mdjwel
mdjwel / get_user_role.php
Last active September 18, 2018 05:29
Get the user role in WordPress
<?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] : '';
}
@mdjwel
mdjwel / post_titles_array.php
Created August 4, 2018 06:26
Get post all post titles of a post type in a associative array of post_title => ID pair in WordPress
<?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;
@mdjwel
mdjwel / icon-class-to-icon-name-array.php
Created July 24, 2018 21:08
Convert icon classes to icon names.
<?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);
@mdjwel
mdjwel / wc_featured_prodcuts_query.php
Created July 22, 2018 09:52
Get WooCommerce featured products Query
@mdjwel
mdjwel / cf7_remove_autop.php
Created July 4, 2018 06:55
Remove auto p from Contact Form 7 shortcode output
<?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;
}
@mdjwel
mdjwel / custom_post.php
Last active June 28, 2018 05:15
WordPress custom post register class
<?php
// event.pt.php
/**
* Use namespace to avoid conflict
*/
namespace PostType;
/**
* Class Portfolio