Skip to content

Instantly share code, notes, and snippets.

@wpjess
wpjess / wp-loop-taxonomy-term.txt
Created April 23, 2020 16:48
Loop by taxonomy term
<?php
$_terms = get_terms( array('TAXONOMY-NAME') );
foreach ($_terms as $term) :
$term_slug = $term->slug;
$_posts = new WP_Query( array(
'post_type' => 'POST-TYPE-NAME',
'posts_per_page' => 200,
'tax_query' => array(
@wpjess
wpjess / wp-loop-post-type.txt
Created April 23, 2020 16:49
Loop by post type
<?php $paged=(get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array('post_type'=>'slides', 'showposts'=>-1, 'posts_per_page' => 1, 'paged' => $paged )); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$image = get_post_meta($post->ID, 'slide_image', true);
?>
<div class="item"><img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" title="" /></div>
<?php endwhile; endif; ?>
@wpjess
wpjess / wp-loop-basic.txt
Created April 23, 2020 17:03
WP standard loop
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$title = get_post_meta($post->ID, 'page_title', true);
?>
<?php endwhile; endif; ?>
///////////////////////////////////////////////////////////////
//////////////////// ADD POST TYPES /////////////////////////
///////////////////////////////////////////////////////////////
require_once(TEMPLATEPATH . '/post-types/slides.php');
// require_once(TEMPLATEPATH . '/post-types/another-post-type.php');
add_action("admin_init", "admin_init");
function admin_init(){ }
@wpjess
wpjess / page-meta.php
Last active April 23, 2020 18:29
WP custom meta boxes
<?php
$slides = new_cmb2_box(array(
'id' => 'slides_metabox',
'title' => 'Slides',
'object_types' => array(
'slides',
) , // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
@wpjess
wpjess / jQuery-cookie.js
Last active April 23, 2020 17:29
jQuery Cookie - set upon form submission
///////////////////////////////////////////////////////////////////
// RESIZE IMAGES ON THE FLY
///////////////////////////////////////////////////////////////////
require_once(TEMPLATEPATH . '/functions/resize.php');
@wpjess
wpjess / wp-get-image-id-snippet.php
Last active April 23, 2020 18:30
WP get image ID
<?php $image_id = jess_get_attachment_id_by_url( $image ); ?>
@wpjess
wpjess / wp-login-logo.php
Created April 23, 2020 18:24
WP custom login logo
////////////////////////////////////////////////////////////////////
// LOGIN LOGO
////////////////////////////////////////////////////////////////////
function my_login_logo() { ?>
<style type="text/css">
.login h1 {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png);
padding-bottom: 30px;
background-repeat: no-repeat;
background-position: top center;
@wpjess
wpjess / wp-page-slug-menu-id.php
Created April 23, 2020 18:32
WP page slug as menu ID
/////////////////////////////////////////////////////////////////
/// PAGE SLUG AS MENU ITEM ID
/////////////////////////////////////////////////////////////////
function cleanname($v) {
$v = preg_replace('/[^a-zA-Z0-9s]/', '', $v);
$v = str_replace(' ', '-', $v);
$v = strtolower($v);
return $v;
}