Skip to content

Instantly share code, notes, and snippets.

@qwersk
qwersk / custom_taxonomy.php
Last active June 22, 2017 10:21
ADD CUSTOM TAXONOMY #WP #WORDPRESS
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 );
//create a custom taxonomy name it topics for your posts
function create_topics_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
@qwersk
qwersk / get_custom_taxonomy.php
Created June 26, 2017 04:06
GET CUSTOM TAXONOMY TERMS #WP #WORDPRESS
<?php
$course_terms = get_terms( array(
'taxonomy' => 'course_category',
'hide_empty' => false,
) );
//fprint_r($course_terms);
foreach($course_terms as $course_term){
$course_category_id = $course_term->term_id;
@qwersk
qwersk / query_acf.php
Created June 28, 2017 07:18
QUERY BY ACF FIELD #WORDPRESS
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'document_%", "meta_key LIKE 'document_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
@qwersk
qwersk / pagination_in_single.php
Created June 28, 2017 09:17
PAGINATION IN SINGLE.PHP #WORDPRESS #WP
add_action( 'template_redirect', function() {
if ( is_singular( 'authors' ) ) {
global $wp_query;
$page = ( int ) $wp_query->get( 'page' );
if ( $page > 1 ) {
// convert 'page' to 'paged'
$query->set( 'page', 1 );
$query->set( 'paged', $page );
}
// prevent redirect
@qwersk
qwersk / get_author_posts_url.php
Created June 30, 2017 07:01
GET AUTHOR POSTS LINK #WORDPRESS #WP
$args = array(
'orderby' => 'display_name',
'has_published_posts' => true
);
$res = new WP_User_Query($args);
$authors = $res->get_results();
if (!empty($authors))
{
echo '<ul>';
@qwersk
qwersk / remove_get_param.php
Created July 3, 2017 05:48
REMOVE GET PARAMETER FROM URL #PHP
$query = $_SERVER['QUERY_STRING'];
$query_arr = explode("&", $query);
$count_arr = count($query_arr);
for($j = 0; $j < $count_arr; $j++){
if(strpos($query_arr[$j], "pagen") !== false){
//echo $j . "<br />";
@qwersk
qwersk / github-oauth2-client.php
Created July 4, 2017 05:32
Simple PHP example of using Github's OAuth 2 API
<?php
define('OAUTH2_CLIENT_ID', '');
define('OAUTH2_CLIENT_SECRET', '');
$authorizeURL = 'https://github.com/login/oauth/authorize';
$tokenURL = 'https://github.com/login/oauth/access_token';
$apiURLBase = 'https://api.github.com/';
session_start();
@qwersk
qwersk / add_field_user.php
Created July 4, 2017 08:45
ADD CUSTOM FIELD TO USER PROFILE #WP #WORDPRESS
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="phone">Phone Number</label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your phone number.</span>
@qwersk
qwersk / show_acf_in_admin.php
Created July 7, 2017 10:37
SHOW ACF FIELD IN ADMIN AREA #WP #WORDPRESS
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
'location' => __ ( 'Location' ),
'price' => __ ( 'Price' )
) );
}
add_filter ( 'manage_course_posts_columns', 'add_acf_columns' );
function course_custom_column ( $column, $post_id ) {
switch ( $column ) {
@qwersk
qwersk / set_same_height.js
Last active July 11, 2017 09:44
SET SAME HEIGHT #JS #JAVASCRIPT
function set_same_height(selector){
var max_height = 0;
$(selector).each(function(){
if($(this).height() > max_height){
max_height = $(this).height();
}
});
$(selector).each(function(){
$(this).height(max_height);