Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / current_url.php
Created June 20, 2017 04:36
GET CURRENT URL #PHP
function request_url()
{
$result = ''; // Пока результат пуст
$default_port = 80; // Порт по-умолчанию
// А не в защищенном-ли мы соединении?
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']=='on')) {
// В защищенном! Добавим протокол...
$result .= 'https://';
// ...и переназначим значение порта по-умолчанию
@qwersk
qwersk / get_category.php
Created June 18, 2017 10:56
GET CATEGORY ID #JOOMLA
$app = Jfactory::getApplication();
$input=$app->input;
if ($input->getCmd('option')=='com_content'
&& $input->getCmd('view')=='article' ){
$cmodel = JModelLegacy::getInstance('Article', 'ContentModel');
$catid = $cmodel->getItem($app->input->get('id'))->catid;
echo $catid;
}
// 163 - necessary category id
// "category" - taxonomy name
$children_id = get_term_children(163, "category");
foreach($children_id as $child){
$term = get_term_by("id", $child, "category");
$id = $term->term_id;
$name = $term->name;
$count = $term->count;
}
@qwersk
qwersk / get_subcategory_items.php
Created June 15, 2017 07:48
GET SUBCATEGORY ITEMS FROM CUSTOM TAXONOMY #WP #WORDPRESS
$publicationsWithoutTerms = new WP_Query(array(
'post_type' => 'doc',
'tax_query' => array(array(
'taxonomy' => 'category',
'field' => 'term_id',
'operator' => 'NOT IN',
'terms' => get_terms('category', array(
'fields' => 'ids'
))
))
@qwersk
qwersk / .htaccess
Created June 6, 2017 09:09 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/