Skip to content

Instantly share code, notes, and snippets.

View sectsect's full-sized avatar
💭

sect sectsect

💭
View GitHub Profile
@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."'
@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 / 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 / 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 / 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 / get_the_terms_orderby_termorder.php
Last active December 9, 2016 17:34
"get_the_terms" to the order of the "term_order". (order by ASC.)
<?php
/*==================================================
"get_the_terms" to the order of the "term_order". (order by ASC.)
================================================== */
function get_the_terms_orderby_termorder($taxonomy){
global $post;
$terms = get_the_terms($post->ID, $taxonomy);
$array = array();
foreach($terms as $term){
$array[$term->term_order] = (object)array(
@sectsect
sectsect / functions.php
Last active February 12, 2016 10:14
Remove "administrator" user from "get_users()" on wordpress.
<?php
function remove_administrator($users)
{
foreach ($users as $key => $user) {
$cap = reset($user->roles);
if ($cap === 'administrator') {
unset($users[$key]);
}
}
return $users;
@sectsect
sectsect / functions.php
Last active March 20, 2016 19:27
Wordpress: Split the single page for each array without "<!--nextpage-->" on the template. Supported the preview page.
<?php
function is_single_paged($page){
global $wp_query;
if(!is_preview()){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
}else{
$pagenum = $_GET['paged'];
$paged = ($pagenum) ? $pagenum : 1;
$wp_query->query = array('p' => $post->ID, 'page' => $paged, 'preview' => true, 'post_type' => get_post_type() );
$wp_query->set('paged', $paged);
@sectsect
sectsect / index.php
Created April 2, 2016 14:43
Japanese Settings For jQuery-Form-Validator
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.43/jquery.form-validator.min.js"></script>
<script>
var japanese = {
errorTitle: 'フォームの送信に失敗しました',
requiredFields: 'すべての必須フィールドに答えていません',
badTime: '時間が正しくありません',
badEmail: 'メールアドレスが正しくありません',
badTelephone: '電話番号が正しくありません',
badSecurityAnswer: 'セキュリティの質問の答えが正しくありません',
@sectsect
sectsect / functions.php
Created May 11, 2016 19:50
Wordpress: Sort users by numeric value in Users Screen @ https://foxland.fi/sort-users-by-numeric-value-in-users-screen/
<?php
/**
* Add new user column: Expire Date.
*
* @since 1.0.0
* @return array $columns
*/
function prefix_expire_date_column( $columns ) {
$columns['expire_date'] = __( 'Expire Date', 'text-domain' );
return $columns;