dimanche 30 novembre 2014

Output results of get_post_type using orderby


Is it possible to list the output of get_post_type alphabetically in the following:



<?php
$post_type = get_post_type_object( get_post_type($post) ); // GET SINGULAR NAME
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'objects'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types($args, $output, $operator);
echo '<select class="selectboxSingle" name="post_type">';
foreach ( $post_types as $post_type ) {
$exclude = array('phase1','phase2');
if(TRUE === in_array($post_type->name,$exclude)){
continue;
}
// Note: I think you need to use query_var here, rather than slug.
echo '<option value="'.$post_type->query_var.'">' . ucfirst($post_type->labels->singular_name) . '</option>';
}
echo "</select>";
?>




Multisite creating a page in a subdomain site redirects to the main site


Everytime I am creating a new page on my subdomain site, then I view the page, I am redirected to the page of my main site and the subdomain url is appened in my main site url.


So example. My main site is http://site.com and my subdomain site is http://another.site.com


When I created a new page at http://another.site.com say Sample Page with a slug of sample-page , when I view the page, I am redirected to



http://ift.tt/1ysQ16V


What's wrong with this?


Your help would be greatly appeciated!


Thanks!





Turn off https in Wordpress 4


I have a site that uses wpmegamenu to direct people to several non-wordpress pages in an iframe.


I just upgraded to 4.0.1 and it moved everything to https. (which is great!) But this means that the pages that get shown in an iframe are blocked as a mixed content error.


Is there a way to turn off https and have all the fun of 4.0.1 without the https? (So that we can upgrade the pages that lag behind in security without holding up the man thrust of the action.)


I've tried changing wp-config.php and adding define('FORCE_SSL', false); but it made no difference.


There is an option in the settings page wordpress-https_secure_external_urls but it is serializd. It seems to be a place to whitelist http pages, but I have no idea how to get urls onto that list.





White screen of death on my website


I have a working WordPress site on my localhost but when I upload it to the server, it shows a white screen. I have tried removing all the plugins and themes but the screen is still white. Please guide me. Thanks. Here is the link.





Hello I Cant open my Modal What are the Possible solution



<style>
#lc_table
{font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
#lc_table th {border-color: #729ea5;font-size:12px;background-color:#acc8cc;border-width: 1px;padding:1px;border-style: solid;text-align:left;width}
#lc_table tr {background-color:white; border-color: #729ea5}
#lc_table td {font-size:12px;border-width: 1px;border-style: solid;border-color: #729ea5;}
#lc_table tfoot tr td {padding:5px 5px 5px 5px;background-color:#acc8cc }
</style>
<script type="text/javascript">

$(document).ready(function(){
$('tr').click(function(){
$('myModal').modal('show')

});


}); prepare($query); $result->execute(array($vw_interest)); $row = $result -> fetch(PDO::FETCH_NUM); $lc_no = $row[0]; ?> Interest List

<div style="width:auto;height:300x;border-bottom:1px solid #B2DFEE;overflow-y:scroll;">
<form id="myform2" name="myform2" action="interest_view.php" method="get">
<table id="lc_table" style="border:1px solid;">


# Interest Amount (USD) Conversion Rate Interest Amount (Php) 2% EWT Opening Charges 2% EWT Bank Guarantee 2% EWT Other Bank Charges 2% EWT Notary Fee 2307 Control No Doc Stamps Fee OR No Cable Fee Internal No ADV Back Amount Final TND

</tr>
<?php
$ctr = 0;
$query2 = "select interest_no, date_format(date_paid, '%m/%d/%Y'), status_id, principal_no, format(dollar_interest_amount,2), conversion_rate, format(interest_amount,2), interest_ewt,
opening_charges, opening_charges_ewt, bank_guaranty, bank_guaranty_ewt, other_bc, bc_ewt, notary_fee, controlno, doc_stamps_fee, or_no, cable_fee, internal_no, adv, back_amount, final_tnd,
start_date, end_date
from lc_interest WHERE principal_no = ?";
$result2=$db->prepare($query2);
$result2->execute(array($vw_interest));
$count=$result2->rowCount();
while ($row2=$result2->fetch(PDO::FETCH_NUM))
{
//onClick="DoNav('interest_view.php?interest_id=<?php echo $row2[0];,target='_blank'
//window.open('interest_view.php?interest_id=<?php echo $row2[0];&vw_interest=<?php echo $row2[0];,target='_self')
//onclick="DoNav('interest_view.php?interest_id=<?php echo $row2[0];,target='_blank'"
$ctr = $ctr + 1;
?>
<tr class="easyui-tooltip" id="<?php echo $row2[0];?>" title="Click to edit interest" >
<td style="width:2%; text-align:center;"><?php echo $ctr; ?></td>
<td style="width:7%; text-align:right;"><?php echo $row2[4]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[5];?></td>
<td style="width:7%; text-align:right;"><?php echo $row2[6]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[7]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[8]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[9]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[10]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[11]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[12]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[13]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[14]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[15]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[16]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[17]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[18]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[19]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[20]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[21]; ?></td>
<td style="width:5%; text-align:center;"><?php echo $row2[22]; ?></td>


</tr>
<?}?>
</table>
</div>
</form>
</div>


$interest_id = $_GET['interest_id']; if ($interest_id){ $int = "modal:true,closed:false"; } else { $int = "modal:true,closed:true"; } $sql = "SELECT interest_no, interestusd, conversionrate, interestphp, interestphp_ewt, openingcharges, openingcharges_ewt, bankguarantee, bankguarantee_ewt, otherbankcharges, otherbankcharges_ewt, notaryfee, ctrlno2307, docstamps, orno, cablefee, internalno, adv, backamount, finaltnd FROM lc_interest WHERE interest_no = ?"; $result = $db -> prepare($sql); $result -> execute(array($interest_id)); $row = $result -> fetch(PDO::FETCH_NUM); for ($i = 0; $i < 20; $i++){ $object[$i] = $row[$i]; } ?> INTEREST DETAILS "> Interest Amount (USD) : "> Conversion Rate : "> Interest Amount (Php) : "> 2% EWT : "> Opening Charges : "> 2% EWT : "> Bank Guarantee : "> 2% EWT : "> Other Bank Charges : "> 2% EWT : "> Notary Fee : "> 2307 Control No : "> Doc Stamps Fee : "> OR No : "> Cable Fee : "> Internal No : "> ADV : "> Back Amount : "> Final TND : "> Reset






Vertical Mill Distinguishes in Powder Production


With the developing of economic, the social quantity demand and production size of various non-metal ore, cement, building material, etc. is expanding with the rapid increase of material crushing and grinding. Zenith mainly supplies the crushing and grinding craft. The ore exploited from the ore mountain need the process of crushing, which can make the big sized material into some dimensional small granule. And this crushing process needs the jaw, cone and impact type crusher and other mining equipment. The crushed small granule is delivering via belt conveying machine into grinding mill to achieve the grinding with the mesh from 30 to 400. If it is specially required, the fineness granule can reach 2000-3250 mesh, which increases the manufacturing capacity and ore selecting efficiency rapidly. Also, it can increase the economical benefit prominently for ore mine, ore selecting factory, cement factory, etc. In the cement industry, zenith's vertical roller mill is used in the end process of cement powder grinding with the power saving of 20%-30% compared with ball grinder and 30%-40% power saving when it is used in slag powder grinding. The vertical roller mill can meet different requirement of low consumption and high output. Also it has the obvious advantage in environment and power saving, especially in the “twelfth five” plan of cement industry’s combination and reconstruction. zenith's vertical mill is widely used in cement industry because of its super-high output, reliability, easy repair, etc. ,which brings big benefit for cement industry. As the international first-level leading enterprise especially in its research & development, manufacturing and sales, zenith is the provider for rocks and ore processing equipment and solution for system. It autonomously researches and develops the kernel production such as mobile crushing plant, crusher, sand making machine, vertical roller mill, European mill, which has won many national patents praise. It is in the first line to pass through the ISO9001:2000 authentication and European CE certification, which becomes the first choice for powder grinding, coal powder milling, slag for micro powder processing in building, construction material, ore mine, metallurgy and all kinds of non-metal ore, etc.





Send checkout page custom field in order email


i have added option box custom field in checkout page using bellow snippet hook's and function.when user order the product that option box custom field value displaying in backed admin panel but i am not able send that field in order email.


The code or function for sending custom field value i have added in bottom side of this question.


Can any body guide me to send this custom field in order email for both user customer and site admin.



// Add a new checkout field
function kia_filter_checkout_fields($fields){
$fields['extra_fields'] = array(
'some_field' => array(
'type' => 'select',
'required' => true,
'label' => __( 'Some field' ),
'options' => array(
'Newspaper' => __('Newspaper Ad', 'woocommerce' ),
'Facebook' => __('Facebook', 'woocommerce' ),
'Twitter' => __('Twitter', 'woocommerce' ),
'Email' => __('Email', 'woocommerce' ),
'Poster' => __('College Poster', 'woocommerce' ),
'SMS' => __('SMS', 'woocommerce' ),
'Telephone' => __('Telephone Call', 'woocommerce' ),
'Friends' => __('Friends', 'woocommerce' ),
'Others' => __(' Others', 'woocommerce' )
)
)
);

return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'kia_filter_checkout_fields' );

// display the extra field on the checkout form
function kia_extra_checkout_fields(){

$checkout = WC()->checkout(); ?>

<div class="extra-fields">
<h3><?php _e( 'How did you learn about us?' ); ?></h3>

<?php foreach ( $checkout->checkout_fields['extra_fields'] as $key => $field ) : ?>

<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>

<?php endforeach; ?>
</div>

<?php }
add_action( 'woocommerce_after_order_notes' ,'kia_extra_checkout_fields' );

// save the extra field when checkout is processed
function kia_save_extra_checkout_fields( $order_id, $posted ){
if( isset( $posted['some_field'] ) ) {
update_post_meta( $order_id, '_some_field',
sanitize_text_field( $posted['some_field'] ) );
}
}
add_action( 'woocommerce_checkout_update_order_meta',
'kia_save_extra_checkout_fields', 10, 2 );

// display the extra data in the order admin panel
function kia_display_order_data_in_admin( $order ){ ?>
<div class="order_data_column">
<h4><?php _e( 'Extra Details', 'woocommerce' ); ?></h4>
<?php
echo '<p><strong>' . __( 'Some field' ) . ':</strong>'
. get_post_meta( $order->id, '_some_field', true ) . '</p>'; ?>
</div>
<?php }
add_action( 'woocommerce_admin_order_data_after_order_details',

'kia_display_order_data_in_admin' );


In bellow snippet Function which i am using to send custom field value in order email



/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

function my_woocommerce_email_order_meta_keys( $keys ) {
$keys['How did you hear about us?'] = $field;
return $keys;
}




Looking to create a combination blog and paid online course site, like http://chrisoatley.com


I've used Wordpress a long time, and I'm fairly intermediate in knowledge/experience...


This site, www.chrisoatley.com provides a pretty good example of what I'm looking for. Once a user logs in to the paid portion of the site, there's a list of courses. As payments are recurring, the next set of videos unlocks automatically each month.


Does anyone have a rough idea of how this site is built, and how to setup automatically unlocked pages each time a member pays? Also looking to have this sort of module seperate/behind a paywall form the main site, which will have free content, blog posts and sales pages for the course.


Really appreciate the assistance!





BuddyPress display css on xprofile fields


I've been searching for hours now and I can't seem to local a very specific action involving Xprofiles. What I would like to achieve is having an xprofile field with a dropdown option that changes the css of the users profile depending on the options chosen in the dropdown.


So if a user selects Red in a dropdown menu, the body of the page gets a red background (not the page background - since I know there's a plugin for that already).


Any help would be much appreciated.





Displaying custom post types in front end


I am trying to wrap my head around custom post types. What I am trying to achieve is a simple branch listing. There is a dealers menu that has drop downs with regions. When you click on a region I just want it to list branches within the region. Nothing fancy, no maps, just plain text with branch name and contact details + address. Something like this:


Branch Name

Contact Person

Address

Contact number




Branch Name 2

Contact Person 2

Address 2

Contact number 2


I have used custom post UI plugin and another one that lets me add this data in the backend. I can't for the life of me figure out how to display it in the frontend.


I don't want it to act like a post where it lists everything and you click on it for more detail. It should just display as above when you click on a region from the dropdown. Is there a plugin that would do this or do you have to hard code it?





Form Plug-in for flight reservation website


Can someone recommend a suitable form plug-in? I have been search for a suitable one but couldn't find one. This is a flight reservation website. Once the visitor Enter the requirement it will be submitted to a assigned Email


The Following fields will be created



  1. Name (text)

  2. Telephone (Number)

  3. Email (Email)

  4. Oneway, Return, Multi (radio select)

  5. Departure (calendar), Arrival (calendar)

  6. Departure (list) Arrival (list) – There is around 2800+ destinations so I think I will be this to be generated from a database since a dropdown will be very long.

  7. Adults (0-9) Children (0-9) Infants (0-9)

  8. Other Queries (text area)

  9. Send Queries (submit button)


Thank you very much,





Update Wordpress Profile Field From Buddypres


everyone..! I have install buddypress on my blog. I want all users and contributors have a single profile on Buddypress. I mean that I want contributor able to update their wordpress profile field such website, Author Bio, and extra from Buddypress without login dashboard. Anyway, could I do that..? Thanks





Loading custom CSS


I've done some searching and can't seem to find the appropriate solution for a particular problem I'm having. I've created an option within one of my themes that allows the user to edit any element such as h1, p, divs, etc. The user can also add styling and I basically just build up a string of identifiers and the styling that the user has chosen.


What's the best way to load this css string? Is it best to just have it as a function call before , or should I programmatically create a 'custom.css' file that then gets enqueued after 'style.css'? I worry about creating a 'custom.css' file just in case permissions become an issue.





How does the Walker class works?


Can someone explain me how the walker class works and does the methods inside the class always needs to overload the parent method?





Can I hook inside another hook?


My question is that when we hook to a certain action using the oop way for example



class My_Plugin_Class {
public function __construct( ) {
add_action( 'admin_init', array( &$this, 'some_function' ) );
}

public function some_function() {
//do something here
include( 'some_php_file.php' );
}
}


Then inside that some_php_file.php you included



class Some_Class_Again {
public function __construct( ) {
add_action( 'init', array( &$this, 'another_function' ) );
}

public function another_function() {
//do something here like enqueue script
}
}


is this possible to do? that you hooked a method in your class in an action hook and then inside that method you included another class file making or hooking into another action hook. because when I tried it nothing's happening in the second class. I just want to know if this is possible, if it is am I doing something wrong? or if it's not please tell me why. I have this in mind for quite some time now.





Custom single template for a specific category


What is the best way (performance & code structure) to create a custom template for a WordPress Post, which belong to a specific category? I realized that you can’t just create single-catname.php.


So far i tried two ways to change the template. But which one (or another one) is the best?


EDIT:


Any idea how to include all the sub/parent and so on categories to? I realized right now it only shows the main category...


1. Added to functions.php



function get_custom_cat_template($single_template) {
global $post;
if ( in_category( 'movies' )) {
$single_template = dirname( __FILE__ ) . '/single-movies.php';
}
return $single_template;
}
add_filter( "single_template", "get_custom_cat_template" ) ;


2. Put the following Code in to single.php (instead of all other code) and create a single-template.php (with the code from the single.php) & a custom single-movies.php



<?php
if(has_term('movies', 'category', $post)) {
get_template_part('single-movies', 'movies');
} else {
// use default template file single-template.php
get_template_part('single-template');
}
?>




How to remove_menu_page added by a plugin that appears to have no referenceable slug


How do I remove a menu page that is added by a plugin like this:



add_action('admin_menu', array($this, 'add_menu'));


Where there is no slug. Looking at the plugin code and using the links in the anchors doesn't seem to work:



remove_menu_page( 'admin.php?page=tf_slider_list' );


Any suggestions how to remove these links from the menu? I'm going to be removing it for non-admins, so using it in conjunction with:



function custom_remove_menu_pages() {
remove_submenu_page( 'page.php', 'admin.php?page=tf_slider_list' );
}
add_action( 'admin_menu', 'custom_remove_menu_pages', 999 );




What are the ways to include WebGL Shaders in Wordpress?


How are people including WebGL shaders in Wordpress?


The most common way to use shaders is to use <script id="shader-fs" type="x-shader/x-fragment"> tags in HTML files. It is problematic to include script tags in posts or pages. The type is important, so they can't be enqueued like regular javascript files.


From this Stackoverflow page, the files can be dynamically loaded, but this would require placing files somewhere in Wordpress that could be directly linked.


A third option is to just include the shader source code as a long variable string. This is the most direct method, but it makes using createShaderFromScript methods not work.


What other methods are available for using WebGL shaders in Wordpress?





Adding attribute to the post.php form tag in wp-admin


I need to add a 'novalidate' attribute to the form tag in wp-admin post.php. The post.php code itself does not contain the tag, rendered from elsewhere so wondered where it may be or better yet if possible to add this via the functions.php file?


this is what I need to add in at the end





List Terms by category


I have a custom taxonomy called "portfolio-type". The terms = post_type is "portfolio" and category is "portfolio-type"


I'm trying to fetch related post of the same category of current post



<?php
global $post;
$terms = get_the_terms( $post_id, 'portfolio-type' );
$terms = $terms[0]->cat_ID;
$myposts = get_posts(array('numberposts' => 5, 'offset' => 0, 'post_type' =>'portfolio', 'category__in' => wp_get_post_categories( $post_id, 'portfolio-type' ), 'post__not_in' => array($post->ID), 'post_status'=>'publish', 'order'=>'ASC' ));
foreach($myposts as $post) :
setup_postdata($post);
?>

<?php endforeach; ?>
<?php wp_reset_query(); ?>


The script shows related posts however doesn't show current post. I'm using this code for showing related posts as a sidebar menu.


Any advice?





Different Webhost and using Google Mail server: Is there a better way than SMTP?


Currently my situation is the following:


I am using Wordpress which handles a few things mail related: Registration forms that send a notification and contact form that send a message. However, because the mail server we use it a remote mail server connected to with SMTP, the contact form is confusing. The email that is received by the contact form should say it is from the person who fills the contact form out, but is instead forced to conform to the SMTP email settings and says it is from the SMTP email.


We want to use Google Apps Business and their mail servers, but according to the Gmail API (https://developers.google.com/gmail/api/ and https://cloud.google.com/appengine/docs/php/mail/#Sending_Mail) to connect to these mail servers, we'd have to use SMTP or IMAP.


We know we can create a dummy email for SMTP settings and have the website send using that configuartion, but we need another solution.


Is there a way into making Wordpress think that the Google mail servers are local mail servers so that phpmail can be used properly?





Mashable single post end index page load


can anyone give me hints/tips/tricks how to implement the Mashable index page load at the bottom of single post page ?


If you don't know what i'm talking about, please take a look at this screenshot : http://i.imgur.com/PqTg4dX.png


Any help is appreciated !





My permalinks are not working on new server


I am going nuts trying to figure out the rewrite rule for a site that I am moving. I have an old server danceprarade.org/wp and I want to move it to a new server new.danceparade.org/ (no wp). I have the following .htaccess file on the new server and it doesn't seem to load at all. I have the rewrite rules inspector plugin installed and it show "no rewrite rules were found". The .htaccess is in the route of the wordpress site. I am using centos on the new server and linux on the old server. Php v5.3.13 on old server 5.3.3 on new. Mysql 5.0.81 on old and 5.1.73 on new. Here is the .htaccess on the new server:



RewriteEngine on
#RewriteCond %{HTTP_REFERER} !^http://danceparade.org/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://danceparade.org$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.danceparade.org/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.danceparade.org$ [NC]
#RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
Redirect 301 /EE/index.php, http://danceparade.org/
Redirect 301 /wp/, http://new.danceparade.org/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


I don't understand why it is not picking up anything. Note I only have a vague idea as to how .htaccess works :-(


Any help would be most appreciated.


Thanks/Hal





How can I add few css or js file into my plugin


I want do add few cs and js file into my plugin in admin panel. I create function style:



function style() {
wp_enqueue_style ( 'my-admin-theme', plugins_url ( 'style.css', __FILE__ ) );
wp_enqueue_script ( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', array (), '1.0.0', true );
wp_enqueue_script ( 'uploadfile', 'http://hayageek.github.io/jQuery-Upload-File/jquery.uploadfile.min.js', array (), '1.0.0', true );

}

add_action( 'wp_enqueue_scripts', 'jquery' );
add_action( 'wp_enqueue_scripts', 'uploadfile' );
add_action ( 'admin_enqueue_scripts', 'style' );
add_action ( 'login_enqueue_scripts', 'style' );


When I check source code I see only style.css jquery.uploadfile.min.js. What is wrong ?


King regards





Allow comments without approval for custom content type


I like to have comments be approved being posted, however I have a custom content type that I want comments to go through without moderation. Is this possible with a php function for only the custom content type? Thanks.





How to create a theme customizer 'sub' panel?


One of the cool new features of WordPress 4.0 is the add_panel() method. In my situation, i'd like to create a new panel for theme options, that's very straight forward, but is it possible to create sub panels under the them options panel, for example one for the header, one for body and one for the footer? If so, how would I go about doing it?





Separate blogs for offices


I am trying to create a word press site that will have many offices. Each office will be a custom post type. Is there any way to make this work so every office can have their own blog that follows the navigation structure of


http://site.com/offices/office-name/blog


An single posts would be


http://site.com/offices/office-name/blog/postname


I realise that there is probably a multi-site solution , but is there a way to do this using CPTs ?





How do I really disable comments?


I've been on a wordpress hiatus for the past 8 months and have never had to deal with building a website for an actual client. Though, no matter what I tried/how I tried to disable comments, I would always get spammers commenting. What can I do to make sure that comments are really disabled... and what can I do if I want to enable them, but spam gets too much. In essence... what is the industry standard to deal with this?





Navigate posts with different post type that are in the same categories


I created two custom post types that share the same category taxonomy. I'm using next_post_link() and previous_post_link() to navigate through posts with the same category but it only works for individual post types.


I found the following code that links post types but there is no option for next and previous post to be within the same taxonomy/category as the current post.



/*
* Replacement for get_adjacent_post()
*
* This supports only the custom post types you identify and does not
* look at categories anymore. This allows you to go from one custom post type
* to another which was not possible with the default get_adjacent_post().
* Orig: wp-includes/link-template.php
*
* @param string $direction: Can be either 'prev' or 'next'
* @param multi $post_types: Can be a string or an array of strings
*/
function mod_get_adjacent_post($direction = 'prev', $post_types = 'post') {
global $post, $wpdb;

if(empty($post)) return NULL;
if(!$post_types) return NULL;

if(is_array($post_types)){
$txt = '';
for($i = 0; $i <= count($post_types) - 1; $i++){
$txt .= "'".$post_types[$i]."'";
if($i != count($post_types) - 1) $txt .= ', ';
}
$post_types = $txt;
}

$current_post_date = $post->post_date;

$join = '';
$in_same_cat = FALSE;
$excluded_categories = '';
$adjacent = $direction == 'prev' ? 'previous' : 'next';
$op = $direction == 'prev' ? '<' : '>';
$order = $direction == 'prev' ? 'DESC' : 'ASC';

$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type IN({$post_types}) AND p.post_status = 'publish'", $current_post_date), $in_same_cat, $excluded_categories );
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );

$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
$query_key = 'adjacent_post_' . md5($query);
$result = wp_cache_get($query_key, 'counts');
if ( false !== $result )
return $result;

$result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
if ( null === $result )
$result = '';

wp_cache_set($query_key, $result, 'counts');
return $result;
}


Usage



<?php
$prev = mod_get_adjacent_post('prev', array('post', 'custom1', 'custom2'));
$next = mod_get_adjacent_post('next', array('post', 'custom1', 'custom2'));
?>

<?php if($prev) : ?>
<a href="<?php echo get_permalink($prev->ID)?>">&laquo; Go back in time</a>
<?php endif; ?>

<?php if($next) : ?>
<a href="<?php echo get_permalink($next->ID)?>">Next: <?php echo $next->post_title; ?> &raquo;</a>
<?php endif; ?>


How can I navigate the post with the same taxonomy?





php- What can be the best alternative to eval()?


I am using WordPress and for some reasons I need to execute php in my WordPress text widgets. I googled and found this code to add in functions.php file:



add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}


It uses eval() but I dont want to use it as it's a dangerous function and my hosting has this function disabled. What can be the best alternative in my case?


Please don't report is as duplicate, other questions for this topic aren't helping me and it's related to WP





Update Plugin repository with Git


How to Update Plugin Repository with GIT.


I'm using GIT on Windows.





create a simple button with Advanced Custom Fields plugin [on hold]


Does anyone know how to create a button link with the Advanced Custom Fields plugin? I can get the link part to work but I'm not sure how to have the button text changeable by the user?



<a href="<?php the_field('hero_btn'); ?>" class="large button">This text needs to be dynamic</a>


Thanks





Update the published date of a post to custom field date


I'm not sure if this is possible with WordPress or not. I googled a bit and didn't found any answers.


So I need to update the publish date of a custom post type with the custom field date I entered. This update should happen once the custom field date passes the current date.


That is if the custom field date is November 20, the post's publish date should update on November 21st and the updated publish date should be Nov 20.


Any ideas?





While loop with an exception after a count is reached


I'm trying to edit the tag.php page so that it displays all tagged posts (as it normally does) 'but' I want to call a function after the 3rd post in the loop.


Current Code



<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>


Any suggestions on how to insert the following function after the 3rd post in the loop?



<?php echo someFunction() ?>




List posts in alphabetical order


What I'm trying to achieve is to set the list shown in alphabetical order. Any thoughts on how i can successfully achieve this? I have pasted the snippet below for reference.



<ul class="hotel-list">
<?php while (have_posts()) : the_post(); ?>
<?php
$short_description = get_post_meta(get_the_ID(), 'short_search_description', true);
$destination = get_post_meta(get_the_ID(), 'destination', true);
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(250, 9999)); ?></a>
<a href="<?php the_permalink(); ?>"><?php the_title(); echo $destination; ?></a>
<p><?php echo $short_description; ?></p>
<div class="clear"></div>
</li>
<?php endwhile
; ?>
</ul>


Thanks in advance Kenbo





After an attack [on hold]


my site is under a brute-force attack so I cannot view my plugins. I checked in the folder on FTP and there are all the plugins but I cannot active them. Someone can help me? Thanks





Call function on success url woocomerce payment integration


I have integrated a new payment gateway in one of my WordPress woocommerce site using direct pay method. It is redirecting on the payment gateway page successfully from the checkout page but once payment is done succesfully or failed How can I check same? How to call my function on redirection onto my success page?


return url is like: http://www.mysite.com/success or http://www.mysite.com/failed


I want to call success_payment function once it redirect back to my site:



/**
* Successful Payment!
*
* @access public
* @param array $posted
* @return void
*/
function successful_request( $posted ) {
..code goes here
}


Is there any hook available for same? I already read http://docs.woothemes.com/document/payment-gateway-api/ article but no luck.





Wordpress custom form post to different page


I have a site which is developed with PHP and recently I added Wordpress blog(same domain with /blog url) to that.


I would like to implement two extra functions(subscribe/contactus) on that blog which is already existing & handling on PHP site.


I found few plugins like Visual Form Builder to build custom forms and also widgets.


I need to use existing php back-end functions to handle contact-us and subscription functionality in the blog as well. My question is how to change the action url on those custom build forms(in the blog) to post details directly to that existing functions in the PHP site.


Note : i'm very new to wordpress.





How add a group by to the query used by the media library?


What would be the proper way to add a group by to the media library query? What I have tired so far is not working:



add_filter('posts_groupby ', 'limitMediaLibraryItems', 10, 2 );
function limitMediaLibraryItems($groupby) {

if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
$groupby .= " guid";
}

return $groupby;
}




Ad's popping on the homepage?


First of all, there are ad's appearing on my website, and no it wasn't added by me. So it's due to some malware issue(I guess).


I reinstalled wordpress from scratch, including the plugins and theme but nothing helped.


Would anyone be able to help me out? It's appearing only on the homepage. The ad's appear on the header+body+footer and the text in the site is linked to the partner site.


This is really annoying, so please someone kindly help me out :)


Website: http://trinitycollege.lk





Any Twitter plugin doesn't work on wordpress


Any Twitter plugin (Twitter Tools, Import Twitter as post, Tweets as post) doesn't work on my website with Wordpress. I have tested 2 websites onthe same hosting. I tested with 2 Twitters usernames (I have created Twitter API). Any suggestions? Help!!!





Multi-column custom post type (roots theme v7)


for a client I need to create a three column custom post type which collapses into two columns in mobile devices. As the roots theme is using Bootstrap by default, figuring out the RWD bit is not the problem. What I need to do is making it as user-friendly as possible in the backend.


My thoughts are to create some kind of stencil (HTML and CSS) which the client then inserts into the editor, with a feature image being pulled.


I'd like to hear your thoughts on this especially if there would eventually be a better way to achieve this which I haven't thought of.


Cheers!





SyntaxError: syntax error


I'm trying to integrate a google map that displays the location of my posts. I managed to integrate the Google map thanks to the API. But I need to add a script just above the div where I insert my map which doesn't work because of a "SyntaxError: syntax error". Here is the code :


<script type="text/javascript"> var locations = [ <?php $i = 1; while ( have_posts() ) : the_post(); ?> <?php if ( get_post_meta($post->ID, 'latlng', true) !== '' ) : ?> { latlng : new google.maps.LatLng<?php echo get_post_meta($post->ID, 'latlng', true); ?>, }, <?php endif; ?> <?php $i++; endwhile; ?> ]; </script>


Where is it wrong ?


Thanks in advance !





how to upload localhost changes to live server


I have successfully uploaded my localhost wordpress site to a live server and everything works great. I have however needed to make some changes to the site and I did so on my localhost. How can I upload the changes to the live server or do I have to re-upload all the files again and recreate the database etc. That seems like a seriously long way around and surely there must be a more elegant and quicker solution?


Many thanks





Widget area inside a widget


I tried putting dynamic_sidebar('widget-id') inside a custom widget I created and it worked. The only thing I can't figure out is how I can do this through a loop. Is there a way that when the widget is active, it registers a sidebar automatically with the same id as the dynamic_sidebar function inside it?





Display function from functions.php in tag.php


I've added several functions to the functions.php file. I call those functions using a shortcode [shortCode] while in posts, pages, and widgets. But the [shortcode] will not work outside of posts, pages, or widgets. I've tried it in article titles and in other files, but it doesn't work.


I'd like to add a [shortcode] to a function to my tag.php file, but I can't figure it out. Can someone help me?


EXAMPLE FUNCTION



function dynamicContent(){
return 'some dynamic content';
}
add_shortcode('Dcontent', 'dynamicContent');


How can I get the [Dcontent] shortcode to work in the tag.php file?


Thanks, Todd





samedi 29 novembre 2014

How to generate random numeric string for a custom post type?


I have this PHP code to generate a random numeric string:



function generateRandomString($length = 12)
{
global $generatedStrings;
$characters = '0123456789';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
if (isset($generatedStrings[$randomString])) {
$randomString = generateRandomString($length);
}
$generatedStrings[$randomString] = $randomString;
return $randomString;
}

$generatedStrings = array();

foreach(range(1, 100000) as $num) {
echo "\n".$num."\t : ".generateRandomString();
}


I was wondering if anyone could help figure out how to integrate this code with WordPress to auto-generate strings as slugs for a custom post type.


Any guidance you can provide is appreciated!





WooCommerce Product Categories With Description And Thumbnail


I am using the below codes to show all WooCommerece Parent Products categories with title and link on a page. But I want to show WooCommerece Parent Products categories description, thumbnail and post count in it too. So how I can get those too along title and link.



<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
?>
<?php $all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
?>
<?php echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>'; ?>
<?php
}
}
?>


Note: I will give warm welcome to those who also help me to short the upper code more as I think it have some extra stuff...





Get x recent posts by author?


So I have ten authors on my site, and I want to designate a section where it shows the ten authors and their 5 latest posts in the form of the post title linking to the post.


I tried using the following



<?php get_most_recent_post_of_user( $user_id ); ?>


But it doesn't work, so I'm feeling a bit lost.


Any advice/suggestion?





List all pages using a specific template on a page


I just created a WordPress page called Latest Blog Posts where I want to list, in chronological order, all pages from my website using the template name "Blog". The list should contain the title of the pages, the date the pages were published and their thumbnail images.


Is there any WordPress built-in function/query that could easily allow me to do so? If not, how should I proceed when creating new blog pages (using the template "Blog") to allow me to list them all on a single page.


Most of my pages do not use the template name "Blog" but I recently decided to ad a blog section to my website and would love to be able to list all my blog posts on a single page.





How do I override plugin templates and stylesheets?


Can I easily override plugin's templates and stylesheets in my child theme or does the plugin have to provide functionalities to do this?


I have overridden template files for some of the plugins in the past but some of them don't seem to work.





How to add an if statement for one of the custom fields on the following loop?


I have a bunch of custom fields on one of my post types, that is displayed randomly but in a fixed order. The names of the custom fields are always the same, and for every loop there is an increasing counter added to the custom field names.


Like this:



custom_text
custom_text1
custom_text2

custom_image
custom_image1
custom_image2

custom_video
custom_video1
custom_video2


The problem is, there is one field that begins with the number one, like this:



custom_special1
custom_special2
custom_special3


Right now, it's impossible to change this behaviour. Problem is, this makes the custom_special fields show up in the wrong place of the output, the first one shows up together with the fields with the number 1 at then end, instead of with the empty ones.


I need to tweak the code below with some kind of if statement, that says something like:


if $custom_special . $counter {output the result one step down}


Here's my code, I hope some of you gurus out there can help me with a solution!



// max custom field index
$number = 40;
// the counter
$counter = '';
// the meta keys to check for
$keys = array(
'custom_text',
'custom_image',
'custom_video'
);
// all our custom field values
$custom_fields = get_post_custom( get_the_ID() );

// loop over our counter
while( $counter < $number ){
// loop over each of the keys
foreach( $keys as $key ){
// check if a custom field with key + counter exists
if( isset( $custom_fields[ $key . $counter ] ) ){
// output the field
// values will be in an array, 0 is the first index.
// you can loop over these as well if you have multiple values.
echo $custom_fields[ $key . $counter ][0];
}
}
// increment the counter
$counter++;
}


Thanks a lot!


// Jens.





Problem with logo on mobile devices


I've got a problem with the logo in navbar. On the computers it looks like it should. Here's my site - http://goo.gl/EpkGpz - as you can see, logo looks awesome. I am using theme called Hueman. I put the image in the navbar by using this code:



li#menu-item-1735 a {
display: block;
background-image:url('mylogo.png');
background-repeat: no-repeat;
width: 125px;
height: 20px;
text-indent: -9000px;
}


The problem begins on the mobile devices. Here's the screen how it looks right now - i.imgur. com/R6AtzbO.png


It should be like this - i.imgur. com/mnbfSYS.png (the search box icon must be moved to the right) or like this - i.imgur. com/QoZgmWr.png. I prefer the first option, but i will be glad if someone can help me with any of these versions. You can check how does my site look on mobile devices here - mobiletest. me


EDIT: I think i figured out why the logo isn't showing up correctly. My logo is just a replaced link in menu (menu-item), so i think that's the reason why logo isn't showing up on mobile devices. Does anyone have any suggestions, how to apply logo in topbar without using "menu-item" attribute?


Best regards, i hope someone will find some time to help me solve my problem.





Preventing PHP Execution in Parent Theme


I have set up a child theme to make custom changes to my site without having them erased every time I update. One change is to remove a wrapper that displays the title of the page with a lot of white space around it in the "content-hero.php" file. The code from the parent file is:



<div class="hero <?php echo edin_additional_class(); ?>">
<?php if ( ! is_page_template( 'page-templates/front-page.php' ) ) : ?>

<?php the_title( '<div class="hero-wrapper"><h1 class="page-title">', '</h1></div>' ); ?>

<?php else : ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( 1 == get_theme_mod( 'edin_title_front_page' ) ) {
the_title( '<header class="entry-header"><h1 class="page-title">', '</h1></header>' );
}
?>
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'edin' ),
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
?>
</div><!-- .entry-content -->
<?php edit_post_link( __( 'Edit', 'edin' ), '<footer class="entry-footer"><span class="edit-link">', '</span></footer>' ); ?>
</article><!-- #post-## -->

<?php endif; ?>


I simply comment all of this out in the parent file using <!-- -->


But every time I update the theme this will be erased. Is there a code I can put in the functions.php (or style.css) file in the child theme to prevent this from loading?





Woocommerce single product show in modal Bootstrap


I am designing a WooCommerce theme and I need to know how I can show single -product into a modal Bootstrap 3 and no display on a single page . How I can fix this? This is an example :


http://demos.jckemp.com/woocommerce-quickview/





Getting logout confirmation page despite nonce


I implemented an Ajax login on my site, and that part works great, but I'm having issues with the logout.


For the logout, I'm using the default link:



<?php echo wp_logout_url( home_url() );?>


But when I click on it, sends me to a confirmation page "You are attempting to log out of My Site Do you really want to log out?".


I've compared the links, and the link in the confirmation page is identical to the link I'm using in my template.


I'm guessing it has to do with the Ajax login, because it only happens when I click logout on the same page where I just logged in. If I go to a different page, the logout works fine.


Must I refresh the page after login? Is there a workaround, so I can keep my Ajax, and avoid redirecting after login?





Woocommerce Measurement Price Calculator- Remove Pirce for non logged in users


Is there any way to remove the price that the Measurement Price Calculator generates for not logged in users?


Would like it to say log in or register to view


Here is the way it works http://demo.foxrunsoftware.net/woocommerce-measurement-price-calculator/shop/wallpaper-by-the-roll-based-on-room-dimensions/


Thanks!





Wordpress Taxonomy Key Length


I want to change the taxonomy key length to support keys greater than 32 chars. I have adopted a custom WooCommerce store where some WP core files wp-includes/taxonomy.php have been edited to change if ( strlen( $taxonomy ) > 32 ) to if ( strlen( $taxonomy ) > 255 ). Is there a way I can abstract this away from the core files but still allow for the key length to be greater than 32?





Which PHP structure is good for storing data in the WordPress option table? And what about PHP plugin PHP structure?


I searched too much about that but can't find resonable answer of that question


I am creating a WordPress plugin that has so many options that I need to store so to store data using option API which structure is good StdClass or Array?


I want to know answer based on simplicity and ease to manage structure and I heard about ArrayObject too can I use this is my plugin structure? And I want to know about which PHP pattern is good for plugin structure: singleton or simple class?





WordPress: Custom SQL Query: Get all posts with category id and a concated list of tags on each post


I am trying to select all posts from a WordPress database, include few fields on each post, but most importantly I would like to also select the "category id" or each post, and ALL the tags that belong to this post, as a CSV value, i.e.: tags="foo,bar,bla"


So far I am using 2 queries, but I would like to combine them if possible.


I can select all the tags like this



SELECT
wp_terms.name as _name, # get the tag name
wp_term_relationships.object_id as _pid # get the post id that it belongs to

FROM wp_terms

LEFT JOIN wp_term_relationships ON wp_terms.term_id = wp_term_relationships.term_taxonomy_id

LEFT JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id

WHERE wp_term_taxonomy.count > 0
AND wp_term_taxonomy.taxonomy = "post_tag"


Then I select all posts


but also figure out to which category each post belongs to, note the _cid



SELECT
wp_posts.ID as _pid,
wp_terms.term_id as _cid # that's the category id

FROM wp_posts

# all this to get the _cid
LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_ID
LEFT JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
LEFT JOIN wp_terms ON wp_terms.term_id = wp_term_taxonomy.term_id

WHERE
wp_term_taxonomy.taxonomy = "category" # filter the terms by category taxonomy

AND wp_posts.post_type="post"
AND wp_posts.post_status="publish"


Then in my code logic, I create a map of all posts using the post ids as keys, then add an array or a string value, call it tags, then I push the tags that belong to that post id on it. It works, but it's not as efficient, since I have millions of posts, and I would like to support pagination using LIMIT, I would still have to query all tags all the time.


I attempted using GROUP_CONCAT but I failed to get what I want. The main problem I am facing is that both, the category name and the tags are in reality just terms, but I need to concat all the terms of one of them, the taxonomy=post_tag, but not the other, taxonomy=category


An Example of my ideal end result row


Would look something like



| _pid | _cid | _tags |
| 10 | 3 | foo,bar,bla|




Triger a custom menu that belongs to a page, it's childern and a custom post type


In my header template I want set a sub menu that changes depending on what page you are on. So if you are on the About page or one of the About child pages then the sub menu changes to the About menu. If you are on the Members page or one of the Members child pages then the sub menu changes to the Members menu.


So in code it might be something like, if About page or or child page page then call About menu and so on... one issue is that some of the children are custom post types. I can build a custom menu fine with a link to an archive page that has all the custom posts on it but I have no idea what the code would look like?





Create grid type custom post thumbnail slider with flexslider


enter image description here


I am trying to this grid view gallery slider with flexslider. My html code is :



<ul class="slides">
<li>
<div class="photo-1">
<img src="images/photostream/one.jpg" width="101" height="102">
<span class="flex-photoCaption"><a href=""> <i class="fa fa-search"></i></a></span>
</div>
<div class="photo-1">
<a href=""><img src="images/photostream/two.jpg" width="101" height="102"></a>
<span class="flex-photoCaption"> <a href=""><i class="fa fa-search"></i></a></span>
</div>
<div class="photo-1">
<a href=""><img src="images/photostream/three.jpg" width="101" height="102"></a>
<span class="flex-photoCaption"> <a href=""><i class="fa fa-search"></i></a></span>
</div>
<div class="photo-1">
<a href=""><img src="images/photostream/four.jpg" width="101" height="102"></a>
<span class="flex-photoCaption"> <a href=""><i class="fa fa-search"></i></a></span>
</div>
</li>
<li>
<div class="photo-1">
<img src="images/photostream/one.jpg" width="101" height="102">
<span class="flex-photoCaption"><a href=""> <i class="fa fa-search"></i></a></span>
</div>
<div class="photo-1">
<a href=""><img src="images/photostream/two.jpg" width="101" height="102"></a>
<span class="flex-photoCaption"> <a href=""><i class="fa fa-search"></i></a></span>
</div>
<div class="photo-1">
<a href=""><img src="images/photostream/three.jpg" width="101" height="102"></a>
<span class="flex-photoCaption"> <a href=""><i class="fa fa-search"></i></a></span>
</div>
<div class="photo-1">
<a href=""><img src="images/photostream/four.jpg" width="101" height="102"></a>
<span class="flex-photoCaption"> <a href=""><i class="fa fa-search"></i></a></span>
</div>
</li>

</ul>


I am writing :



<ul class="slides">
<?php
global $post;
$photo_args = array(

'post_type' => 'photo_gallery',
'posts_per_page' => -1,
'order' => 'ASC',
);
$photo_querys = get_posts( $photo_args );
?>
<?php foreach($photo_querys as $post) : setup_postdata($post); ?>
<li>
<?php

$element_show = 1;
$element_show = '<div class="photo-1">'. the_post_thumbnail('gallery_image').'
<span class="flex-photoCaption"><a href=" '. get_permalink(). '"> <i class="fa fa-search"></i></a></span></div>';

$element_to_show = 2 * $element_show ;?>
<?php echo $element_to_show ; ?>
</li>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</ul>


Images are showing but there is showing "0" value after the "li" elements


This is from my view source



<li style="width: 120px; float: left; display: block;">
<img draggable="false" src="http://localhost/azadfoundation/final/wp-content/uploads/2014/11/selfdefense8_fs-100x102.jpg" class="attachment-gallery_image wp-post-image" alt="selfdefense8_fs" height="102" width="100">
0
</li>


The below image is the output enter image description here


I know I am going wrong. Can anyone please help ? Thanks in advance.





Index tags for specific posts (including custom)


The following code currently indexes all tags for my site (whether attached to a standard post or a custom post) like so...


http://www.furthereast.com/index/


I want to limit this code to index tags from only a specific custom post (and then taxonomy within that custom post) but I cannot work out what adjustment I need to the initial code (I don't know how to set the $args and I suspect I cannot use get_terms() for custom posts). Would appreciate some help.



$list = '';
$tags = get_terms( 'post_tag' );
$groups = array();
if( $tags && is_array( $tags ) ) {
foreach( $tags as $tag ) {
$first_letter = strtoupper( $tag->name[0] );
$groups[ $first_letter ][] = $tag;
}
if( !empty( $groups ) ) {
foreach( $groups as $letter => $tags ) {
$list .= "\n" . '<div class="index-letter">' . apply_filters( 'the_title', $letter ) . '</div>';

foreach( $tags as $tag ) {
$url = attribute_escape( get_tag_link( $tag->term_id ) );
$count = intval( $tag->count );
$name = apply_filters( 'the_title', $tag->name );
$list .= "\n" . '<li><a href="' . $url . '">' . $name . '</a> (' . $count . ')</li>';
}
$list .= "\n" . '</li>';
}
}
}else $list .= "\n" . '<p>Sorry, but no tags were found</p>';?>




WordPress database error: [Commands out of sync; you can't run this command now]


I have create function with code bellow:



function my_add_new_id ( ) {
global $my_db_connect;
global $my_user;
global $my_wpid;
global $my_wpname;
global $my_wpemail;
global $my_generate_pin;
global $my_generate_pass;
global $my_add_id_message;
global $my_svr_region;
global $GetPass;
$my_user = wp_get_current_user();
$my_wpid = $my_user->ID;
$my_wpname = $my_user->display_name;
$my_wpemail = $my_user->user_email;
$my_generate_pin = my_randomPin();
$my_generate_pass = my_randomPass();
if ( isset( $_POST['my_login'] ) )
{
$options = get_option( 'my_settings' );
$my_svr_region = $options['my_serverregion'];
if ( empty ( $my_svr_region ) ) {
$my_svr_region = 1;
}
$mylogin = $_POST['my_login'];
$mypassold = $_POST['my_password'];
$mypinold = $_POST['my_pin'];
if ( empty ( $mylogin ) || empty ( $mypassold ) || empty ( $mypinold ) ) {
$mytw_add_id_message .= '<div class="my-alert-box myerror"><b>All box must fill</b></div>';
}
elseif ( preg_match ( "/[^0-9a-z]/",$mylogin ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Please use a - z and 0 - 9</b></div>';
}
elseif ( preg_match ( "/[^0-9a-z]/",$mypassold ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Please use a - z and 0 - 9</b></div>';
}
elseif ( preg_match ( "/[^0-9a-z]/",$mypinold ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Please use a - z and 0 - 9</b></div>';
}
elseif ((StrLen($mylogin) < 4) or (StrLen($mylogin) > 10)) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Must use 4 character and no more than 10 character</b></div>';
}
elseif ((StrLen($mypassold) < 4) or (StrLen($mypassold) > 10)) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Must use 4 character and no more than 10 character</b></div>';
}
elseif ((StrLen($mypinold) < 4) or (StrLen($mypinold) > 4)) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Must use 4 character</b></div>';
}
$mypass = $my_generate_pass;
$myname = $my_wpname;
$myemail = $my_wpemail;
$mypin = $my_generate_pin;
$mylogin = StrToLower(Trim($mylogin));
$mypass = StrToLower(Trim($mypass));
$mypassold = StrToLower(Trim($mypassold));
$myname = ucwords(Trim($myname));
$myemail = StrToLower(Trim($myemail));
$mypin = StrToLower(Trim($mypin));
$mypinold = StrToLower(Trim($mypinold));
$garamold = $mylogin.$mypassold;
$garamold = md5($garamold);
$garamold = '0x'.$garamold;
$cPanelOld = $mypassold;
$cPanelOld = md5($cPanelOld);
$garam = $mylogin.$mypass;
$garam = md5($garam);
$garam = '0x'.$garam;
$cPanel = $twpass;
$cPanel = md5($cPanel);
$USER_IP = $_SERVER['REMOTE_ADDR'];
$GetAccountInfo = $my_db_connect->get_results ( $my_db_connect->prepare ( 'SELECT * FROM users WHERE name = %s ;', $mylogin ) );
$GetAccountNum = $my_db_connect->get_var ( $my_db_connect->prepare ( 'SELECT COUNT(*) FROM users WHERE name = %s ;', $mylogin ) );
if ( ( !$GetAccountInfo ) || ( !$GetAccountNum ) || ( !$GetAccountNum == 1 ) ) {
$my_add_id_message .= '<div class="tw-alert-box twerror">FAILED: ID '.$mylogin.' not found</div>';
}
else {
foreach ( $GetAccountInfo as $GetDataUser ) {
$GetLogin = $GetDataUser->name;
$GetPass = $GetDataUser->passwd;
$GetPin = $GetDataUser->qq;
$GetMoney = $GetDataUser->money;
$GetWPID = $GetDataUser->wp_ID;
$GetSvrReg = $GetDataUser->svr_region;
}
$GetSvrPass = $my_db_connect->get_var ( $my_db_connect->prepare ( 'CALL my_acquireuserpasswd ( %s, @ID, @PASS ) ;', $mylogin ) );
$GetPassVarHex = $GetSvrPass;
if ( ( $garamold !== $GetPassVarHex ) || ( $twpinold !== $GetPin ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><span>FAILED:</span> Old Password and Old Pin not match</div>';
}
else {
$my_db_connect->query ( $my_db_connect->prepare ( 'CALL my_add_other_id ( %s, '.$garam.', %s, %s, %s, %s, %s, %s, %d, %d ) ; ', $mylogin, $cPanel, $mypass, $my_wpname, $USER_IP, $my_wpemail, $mypin, $my_wpid, $my_svr_region ) );
$my_add_id_message .= '<div class="my-alert-box mysuccess"><span>SUCCESS:</span> New ID has been added to your account! </div>';
}
}
}
else {
$my_add_id_message .= 'Please Fill This Form!';
}
echo $my_add_id_message;
}


and mysql Procedure and function bellow:



MYSQL PROCEDURE: my_acquireuserpasswd
=======================================
BEGIN
DECLARE passwdtemp VARCHAR(64);
START TRANSACTION;
SELECT id, passwd INTO uid1, passwdtemp FROM users WHERE name = name1;
SELECT fn_varbintohexsubstring(1,passwdtemp,1,0) ;
COMMIT;
END
================================================================
PARAMETER: in name1 VARCHAR(64), out uid1 INTEGER, out passwd1 VARCHAR(64)
================================================================

MYSQL PROCEDURE: my_add_other_id
================================================================
BEGIN
START TRANSACTION;
UPDATE users SET passwd = passwd1,
Prompt = Prompt1,
answer = answer1,
truename = truename1,
idnumber = idnumber1,
email = email1,
qq = qq1,
passwd2 = passwd1,
wp_ID = wp_ID1,
svr_region = svr_region1
WHERE name = name1;
COMMIT;
END
================================================================
PARAMETER: in name1 varchar(64), in passwd1 varchar(64), in Prompt1 varchar(64), in answer1 varchar(32), in truename1 varchar(255), in idnumber1 varchar(32), in email1 varchar(255), in qq1 varchar(32), in wp_ID1 bigint(20), in svr_region1 int(2)
================================================================

MYSQL FUNCTION: fn_varbintohexsubstring
================================================================
BEGIN
DECLARE pstrout VARCHAR(4000);
DECLARE i int;
DECLARE firstnibble int;
DECLARE secondnibble int;
DECLARE tempint int;
DECLARE hexstring char( 16);
BEGIN
IF( pbinin IS NOT NULL) THEN
SET i= 0, cbytesin= CASE WHEN( cbytesin> 0) THEN cbytesin ELSE LENGTH( pbinin) END,
pstrout= CASE WHEN( fsetprefix= 1) THEN '0x' ELSE '' END,
hexstring= '0123456789abcdef';
IF((( cbytesin * 2) + 2> 4000) or( startoffset< 1)) THEN
RETURN NULL;
END IF;
WHILE( i< cbytesin) DO
SET tempint= ASCII( substring( pbinin, i + startoffset, 1));
SET firstnibble= TRUNCATE((tempint / 16),0);
SET secondnibble= tempint % 16;
SET pstrout= CONCAT(pstrout ,cast( substring( hexstring,( firstnibble+1), 1) AS CHAR), cast( substring( hexstring,( secondnibble+1), 1) AS CHAR));
SET i= i + 1;
END WHILE;
RETURN pstrout;
END IF;
RETURN NULL;
END;
END
================================================================
PARAMETER: fsetprefix bit,pbinin varbinary(8000),startoffset int,cbytesin int
RETURN TYPE: varchar(4000)
================================================================


every time i execute the function i always got "WordPress database error: [Commands out of sync; you can't run this command now]"


those error always appear when i execute the function on form. it give WordPress database error: [Commands out of sync; you can't run this command now] on CALL my_add_other_id


i have re-check those Procedure, there is nothing wrong with it. but the message always say can't run my_add_other_id


Perhaps someone can help me.


Thank You





Remove width and height attributes from post image


I don't want that post image is appointed by width and height. Output at the moment:



<img src="image.jpg" alt="image" width="150" height="150" />


It must be:



<img src="image.jpg" alt="image" />


or



<img src="image.jpg" alt="image" width="100%" height="auto" />


I've tried to use the following jQuery script but it doesn't help:



$(document).ready(function(){
$('.single-page-content').find('img').removeAttr('width');
});


In addition, I'm using the following CSS code:



.content .single-page img {
max-width: 100% !important;
min-width: 100% !important;
height: auto !important;
}




Custom front login and registration wordpress php code


I want to be able to allow a user to register/login,forgot password via a front end form


Please don't suggest me any plugin





not able to hook the event for the state of article change to publish for the iOS app push notifications


i have developed an iOS app with wordpress as backend and i have written the server side code for the same.


Now, i need to run my code when ever a post is published. Also i need to create a table to store the ids of the iOS devices so that when ever an new post is published, the notification is sent to all the registered devices automatically.


I am not able to figure out how to do so .


Any suggestion would be grteat.


Thanks in advance!





wp_query: How to retrieve current term slug in custom taxonomy?


Using the WP Types Plugin, I setup a custom post type (slug: portfolio), which has a custom taxonomy (slug: portfolio-category).


The custom taxonomy has three items (slugs: group1, group2, group3) to organize portfolio posts.


On each single portfolio page I am displaying 3 related posts from the same taxonomy term, filtered by slug:



global $post;

$term_list = wp_get_post_terms($post->ID, 'portfolio-category', array("fields" => "names"));

$wpex_port_query = new WP_Query(
array(
'post_type' => 'portfolio',
'showposts' => '3',
'orderby' => 'rand',
'post__not_in' => array($post->ID),
'no_found_rows' => true,
'tax_query' => array(
array(
'taxonomy' => 'portfolio-category',
'field' => 'slug',
'terms' => $term_list,
)
)
)
);


This basically works, but I am wondering if there is a better way than creating a global variable $post? What is the recommended way to handle this?





Child theme not overriding 'includes' folder on server - on localhost it does


I have includes/setup.php on my parent theme, which I successfully override in child theme with includes/setup.php file on localhost development environment.


When I move the files to live server, the file is not overridden. The child theme is active, because css and all the files on child theme root are loaded, but includes/setup.php is not.


What might cause this?





How to query a list of posts titles into the choices for Advanced Custom Fields (Wordpress)?


I have two custom post types in WordPress: Authors and Books. I want to use Advanced Custom Fields to add a checkbox list when I add a new Book. This checkbox list contains the entire list of authors.


My purpose is to create a dynamic list of items (authors) to tick away when creating a new Book, as new authors will be added from time to time. For simplicity, let's focus on Authors' titles.


This image will make things clearer: Admin Dashboard in WordPress


Is there any known way to do it?





How to add taxonomy to Users menu in admin?


I want to create a taxonomy that is related to the users, therefore I'd like to show the taxonomy under "Users" menu within wordpress admin. In codex there's a mention that you can attach taxonomy to "nav_menu_item" but I can't find any working example of how this works. If I use:



register_taxonomy( 'expertise', array( 'nav_menu_item' ), $args );


or



register_taxonomy( 'expertise', array( 'users' ), $args );


it doesn't work.


Any help would be much appreciated.





Method to implement price differentiation based on region selected by visitor


I have a simple wordpress website for a company that delivers services in different cities across the country. I would like visitors to be asked their region when they enter the website, and then when they go to the page with the price list, show the prices based on their region. Can anyone recommend a method to implement this? I looked at various plugins but I found none that seemed fit for the job. I could build a scheme with cookies etc. but my fluency in these things is limited and it seems like a common task, so I would expect an easier method to be available.


Thank you for any suggestions!





Problem with WP_User_Query in Wordpress 4.0.1


Ce résumé n'est pas disponible. Veuillez cliquer ici pour afficher l'article.


What happens when WordPress memory limit is exceeded?


Let's say a WordPress website has the following settings:



  • PHP Memory Limit: 100MB

  • WordPress Memory Limit: 50MB


What happens when the WordPress Memory Limit is exceeded?



  1. Do plugins/themes stop / Do processes fail?

  2. Does the website hang on the back-end/front-end?

  3. Are public website visitors presented error messages or is it all a background affair?


Why is it a bad idea to set it too high?





in the time of local host data to main server import time problem


i make my site at local host wordpress3.6 it databse backup already i have, but time of Import WordPress4.1 in live site following error


Sorry, there has been an error. This does not appear to be a WXR file, missing/invalid WXR version number


give me any solution of this error





SmoothScroll not working in Wordpress


I have been asked to take a HTML website and develop a Wordpress theme out of it. The website uses SmoothScroll so when a button in the footer is clicked, it scrolls nicely to the top of the page. Except now it is in Wordpress, I click the button and it just reloads the page at siteurl.com/#about


The jquery in the .js include (as well as a smoothscroll.js include) was:



$(function() {
'use strict';

$('.scroll').bind('click', function(event) {
var $anchor = $(this);
var headerH = $('#navigation').outerHeight();
$('html, body').stop().animate({
scrollTop : $($anchor.attr('href')).offset().top - headerH + "px"
}, 1200, 'easeInOutExpo');

event.preventDefault();
});
});


And i changed this to put in non-conflict or whatever it is you call it:



jQuery(document).ready(function( $ ) {
$(function() {
'use strict';

$('.scroll').bind('click', function(event) {
var $anchor = $(this);
var headerH = $('#navigation').outerHeight();
$('html, body').stop().animate({
scrollTop : $($anchor.attr('href')).offset().top - headerH + "px"
}, 1200, 'easeInOutExpo');

event.preventDefault();
});
});
});


There are also a couple of other jquery effects that aren't working but jquery is working because some things are ie. toggle to display map etc..


Any suggestions? Could it just be the way it is loading the URL with the slash in between?


Thanks.





wp_login_url not working correctly


I'm working on a project where I need to add a custom link to admin menu, and I'm using the following code for it:



$login_url = wp_login_url();
add_options_page('Login', 'Login Page', 'manage_options', 'loop.php?url='.esc_url($login_url).'');


Here's a thing. The above code is adding following URL to menu:


http://example.com/wp-admin/loop.php?url=http:/example.com/wp-login.php


Instead of:


http://example.com/wp-admin/loop.php?url=http://example.com/wp-login.php


What's different?


It's generating the URL with only http:/ instead of http://


I even tried it without esc_url but it's still not working.


Hope you can help :)





create post using Ajax


I want to create post using Ajax .


I had followed the process from Insert Post using Ajax But i couldn't make it work. please help me out .


Here is the things i did , Please see what I did wrong as i am just a learner .


In WordPress page Template



$j=jQuery.noConflict();
$j(document).ready(function(){
$j("#enqform").validate({
submitHandler: function () {
dataString = $j("#enqform").serialize();
$.ajax({
type: "POST",
url: "http://localhost/wso/wp-admin/admin-ajax.php",
data : {action: "admin_ajax_enqform" }

});
}
})
});
</script>

<form action="<?php the_permalink(); ?>" class="contact-box" id="enqform" method="post">
<label for="firstname">First Name<span class="req">*</span></label>
<input type="text" id="firstname" name="firstname" value="<?php if(isset($_POST['firstname'])) echo $_POST['firstname'];?>" class="required" />

<input type="hidden" name="submitted" id="submitted" value="true" />

<input type="hidden" name="action" value="admin_ajax_enqform" />
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce( 'form-nonce' );?>" />

<input type="submit" id="submit-btn" value="Submit" />
</form>


In WordPress Function.php



add_action( 'admin_ajax_enqform', 'wpse_126886_ajax_handler' );

function wpse_126886_ajax_handler() {

if(isset($_POST['submitted'])) { //validations

if(trim($_POST['firstname']) === '') {
$hasError = true;
} else {
$firstname = trim($_POST['firstname']);
}


// maybe check some permissions here, depending on your app

global $wpdb;
$nonce = $_POST['nonce'];
if ( ! wp_verify_nonce( $nonce, 'form-nonce' ) ) {
die( 'Security check' );
} else {
$new_post = array(
'post_title' => $firstname,
'post_status' => 'publish',
'post_type' => 'post'
);
$pid = wp_insert_post($new_post);
if( $pid ) {
add_post_meta( $pid, 'cpt_firstname', $firstname, true );
}


// send some information back to the javascipt handler
$response = array(
'status' => '200',
'message' => 'OK',
'new_post_ID' => $pid
);


}




// normally, the script expects a json respone
header( 'Content-Type: application/json; charset=utf-8' );
echo json_encode( $response );

exit; // important
}
}


thanks in advance .





Polylang translation of WP Booking Calendar


I've a WP website



http://www.chalupabukovec.cz



with Innovative theme



https://wordpress.org/themes/innovative



and I'm using Polylang plugin for Czech and English translation. Everything works fine except I'm really stucked on translating WP Booking Calendar plugin.


I know there is a automatical translation of this plugin for qTranslate but qTranslate didn't work for me as good as Polylang.


I've read a lot of topics here about string translation like:



pll_register_string($name, $string);



but I really don't know where I can find these strings what I'm looking for. Also there are some .MO/.PO files at WPbookingCalendar plugin directory which are used for translation but are these files anyhow useful for me right now?


Anyone any advice or experience?


Thaaank you :)





Best way to change the Single Template for a specific Category


What is the best way (performence & code structure) to create a custom template for a WordPress Post, which belong to a specific category? I realized that you can’t just create single-catname.php.


So far i tried two ways to change the template. But wich one (or another one) ist the best?


1. Added to functions.php



function get_custom_cat_template($single_template) {
global $post;
if ( in_category( 'movies' )) {
$single_template = dirname( __FILE__ ) . '/single-movies.php';
}
return $single_template;
}
add_filter( "single_template", "get_custom_cat_template" ) ;


2. Put the following Code in to single.php (instead of all other code) and create also a single-template.php (with the code from the single.php) & a custom single-movies.php



<?php
if(has_term('movies', 'category', $post)) {
get_template_part('single-movies', 'movies');
} else {
// use default template file single-template.php
get_template_part('single-template');
}
?>