Skip to content

Instantly share code, notes, and snippets.

View sectsect's full-sized avatar
💭

sect sectsect

💭
View GitHub Profile
@sectsect
sectsect / category-template.php
Created December 17, 2015 14:56
Fix bug "get_the_terms" on wordpress 4.4. you can add the patch yourself to the category-template.php in the wp-includes directory replacing the get_the_terms function.
<?php
function get_the_terms( $post, $taxonomy ) {
if ( ! $post = get_post( $post ) )
return false;
$terms = get_object_term_cache( $post->ID, $taxonomy );
if(false === $terms || empty($terms)){
$terms = wp_get_post_terms( $post->ID, $taxonomy );
if ( ! is_wp_error( $terms ) ) {
@sectsect
sectsect / detect_the_content.php
Last active December 16, 2015 14:22
Detect the_content for Japanese multibyte Characters on wordpress
<?php
function mb_trim($str) {
static $chars = "[\\x0-\x20\x7f\xc2\xa0\xe3\x80\x80]";
return preg_replace("/\A{$chars}++|{$chars}++\z/u", '', strip_tags($str));
}
$content = mb_trim(get_the_content());
if($content === ""){
echo '<p>Empty Content</p>';
}else{
@sectsect
sectsect / inview.js
Created November 27, 2015 18:37
inview.js
jQuery(function(){
var wrap = "#" + thisPanelId + ' .postcontent-inner';
var wrapHeight = jQuery(wrap).outerHeight(true);
var container = "#" + thisPanelId + ' .postcontent-box';
var target = "#" + thisPanelId + ' .postcontent-box .sec-post';
var offset = wrapHeight * 0.25; // 25% Height
jQuery(target).first().addClass("inview");
jQuery(target).each(function(){
var pTop = jQuery(this).position().top - wrapHeight + offset;
var pBtm = jQuery(this).position().top + jQuery(this).outerHeight(true) - offset;
@sectsect
sectsect / example.php
Last active November 4, 2015 12:26
Removing expired dates from an array 💀PHP5.3+
<?php
$array = array(
'1/10/2014',
'1/11/2014',
'1/12/2014',
'1/13/2014',
'1/14/2014'
);
$array = array_filter($array,function($date){
@sectsect
sectsect / get_nextprev_post_link_by_cf.php
Last active October 19, 2015 02:12
Get the Previous / Next Post link by Custom-Field on WP.
<?php
function get_prev_post_cf($link="&laquo; %link", $title="%title", $post_type="post", $meta_key, $meta_value, $label) {
global $wpdb, $post;
$prev = $wpdb->get_row($wpdb->prepare("
SELECT ID, post_title
FROM $wpdb->posts p
LEFT OUTER JOIN $wpdb->postmeta pm on p.ID = pm.post_id
WHERE post_type = '{$post_type}'
AND post_status = 'publish'
AND post_date < '".$post->post_date."'