Audio Player Shortcode

Continue reading “Audio Player Shortcode”

Advertisements

Separate Search Page for Post Type Wp

Paste this code on top of search.php

Create New File like “search-postTypeName.php”


$post_type = $_GET['post_type'];

if ( isset( $post_type ) && locate_template( 'search-' . $post_type . '.php' ) ) {
  // if so, load that template
  get_template_part( 'search', $post_type );
  
  // and then exit out
  exit;
}

Wp Custom Search Form

Search Filter with input hidden fields

<form method="get" action="<?php bloginfo('url'); ?>/">
    <label for="s">Search the site: </label>
    <input type="text" id="s" name="s" value="<?php the_search_query(); ?>">
 
    <!-- Search only these custom post types -->
    <input type="hidden" name="post_type[]" value="page">
    <input type="hidden" name="post_type[]" value="services">
    <input type="hidden" name="post_type[]" value="solutions">

    <!-- Search only this cat with value of 22 -->
    <input type="hidden" value="22" name="cat" id="scat" />

    <input type="submit" value="Search">
</form>

WP Query Arguments

Codex:
http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

Author Parameters – Show posts associated with certain author.
http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters


$args = array(

    // (int) - use author id [use minus (-) to exclude authors by ID ex. 'author' => '-1,-2,-3,']
    'author' => '1,2,3,',
	
	//(string) - use 'user_nicename' (NOT name)
    'author_name' => 'speedy',       
	
	//(array) - use author id (available with Version 3.7).
    'author__in' => array( 2, 6 ),            
	
	//(array)' - use author id (available with Version 3.7).
    'author__not_in' => array( 2, 6 ),    
   

 

Category Parameters – Show posts associated with certain categories.
http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Continue reading “WP Query Arguments”

.htaccess

RewriteEngine On

# Remove .php from files

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ $1.php [L]

# Redirection 404

ErrorDocument 404 https://mfarazali.wordpress.com/page404
ErrorDocument 500 https://mfarazali.wordpress.com/page404

# Disable Directory Access

Continue reading “.htaccess”

Trim Words

wp_trim_words( string $text, int $num_words = 55, string $more = null )

// Example 1
echo wp_trim_words( get_the_content(), 40, '...' );

// Example 2
echo wp_trim_words( get_the_title(), 15 );

// Example 3
$text = 'Some very long text';
$words = 20;
$more = ' […]';
 
$excerpt = wp_trim_words( $text, $words, $more );

Ref:
https://developer.wordpress.org/reference/functions/wp_trim_words/

Remove Visual Composers Junk Print Plain Text


$content=apply_filters('the_content', get_post_field('post_content', get_the_ID()));
echo $content;