samedi 31 janvier 2015

How to internationalize a jQuery output


Good Day everyone,


I'm trying to create an array from data in the Options table of wordpress.


My data all start the same way plugin_order_ and then name of the field information.


Is there a way to extract all those data and create an array with WordPress command?


Or the only way would be to do it with a proper "SQL Query" which I think many people say not to do in WordPress?





How To Get WordPress Categories Link List?


I am trying to make a custom sitemap for my WordPress blogs categories. For that I added the below code in my functions.php file and when I save it, my Blog goes white. Nothing is showing up. I removed this code by going through FTP and then all got again fine.


Now I want to make and use this code. Now can anyone help me out to fix this code?



/* ------------------------------------------------------------------------- *
* Custom Dynamic XML Sitemap Generator For Categories
/* ------------------------------------------------------------------------- */
add_action("publish_post", "cat_create_sitemap");
add_action("publish_page", "cat_create_sitemap");
function cat_create_sitemap() {
$categoriesForSitemap = get_categories(array(
'hide_empty' => 0,
depth => 0,
'hierarchical' => false
));

$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<?xml-stylesheet type="text/xsl" href="sitemap-style.xsl"?>';
$sitemap .= '<urlset xmlns="http://ift.tt/xwbjRF">';

foreach($categoriesForSitemap as $category) {
setup_postdata($category);
$categorydate = explode(" ", $category->category_modified);
$sitemap .= '<url>'.
'<loc>'. get_permalink($category->ID) .'</loc>'.
'<priority>1</priority>'.
'<lastmod>'. $categorydate[0] .'</lastmod>'.
'<changefreq>daily</changefreq>'.
'</url>';
}
$sitemap .= '</urlset>';
$fp = fopen(ABSPATH . "custom-cat-sitemap.xml", 'w');
fwrite($fp, $sitemap);
fclose($fp);
}




How can the user place a custom text string as a placeholder for a plugin


ex: like a user adds {{my-new-plugin}} somewhere in their post, the plugin will read it and add arbitrary text.


I just need help finding the name for this. I can't find this the proper words to put in a search engine.





If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?


So I have 3 custom post types that I want to order by menu_order & have 'date' as the fallback parameter as the majority of posts will have the default menu order of '0'.


It would be nice if pre_get_posts would do this relatively simply (as opposed to something like this - Multiple orderby parameters in pre_get_posts() action), but not looking probable.


This works fine with posts where menu order is set to specific value, where it is 0, the order seems mostly random:



function order_cpt( $query ) {

if ( !is_admin() && $query->is_post_type_archive( array ( 'cat1', 'cat2', 'cat3' ) && query->is_main_query() ) {
$query->set( 'orderby', 'menu_order');
$query->set( 'order', 'DESC' );
return $query;
}
}
add_action( 'pre_get_posts', 'order_cpt');


So the first question which I can't seem to find an answer for is - how are the posts with the same menu order actually being dealt using the function above?


And is pre_get_posts the best route or should I be looking at a custom WP_Query?


Thanks





Warn user that data may be lost for custom pages


When you edit a builtin field in Wordpress like the title and don't save the cahnges, and attempt to go to another link, a warning alert box comes up stating that "changes may be lost if you navigate ...".


How can I make that same box appear for my own pages?


Thanks!





Override core WooCommerce function


I am using WooCommerce, and I have a custom order status to which all new orders are assigned (instead of the default "Processing" status). The WooCommerce admin menu shows a helpful tip showing how many orders you have that need attention, but it only counts "Processing" orders. I want to make the count reflect my custom status.



  • The function that gets the count is wc_processing_order_count() and is defined in woocommerce/includes/wc-order-functions.php. No hooks or filters.


  • The function that displays the count is menu_highlight() and is defined in the class WC_Admin_Menus. The menu_highlight() function is hooked in __construct():



    add_action( 'admin_head', array( $this, 'menu_highlight' ) );



  • The WC_Admin_Menus class is not stored in a global variable when instantiated, and so there is no easy access to that hook.




  • I want to make the change without editing the core WooCommerce files, as they will be overwritten on update.




I was able to remove the 'admin_head' action using this function. Then I could customize the menu_highlight function and the wc_processing_order_count. Is there a more straight-forward way to do this?



function remove_menu_highlight() {
remove_filters_with_method_name('admin_head', 'menu_highlight', 10);
}
add_action('admin_head', 'remove_menu_highlight', 11);
add_action('admin_head', 'custom_menu_highlight', 12);




Function/Class to list categories with checkboxes


I want a list like in the pictue; witch is here - Posts->New->Select Categories


WordPress Add New Post, Categories


At the moment i have this



echo '<select name="pn-cats[]" size="8" style="width: 100%" multiple>';
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$categories = get_categories( $args );
foreach ($categories as $category) {
$option = '<option value="'.$category->cat_name.'">';
$option .= $category->cat_name;
$option .= ' ('.$category->count.')';
$option .= '</option>';
echo $option;
}
echo '</select>';


But i dont like my solution because the categories are not sorted like parent->child in the picture. I need a multi-selectable list.


Do you know any solution? wp_category_checklist don´t work because i need this list in a public page and not in the admin area.





How to change the order of the comment_form fields with css?


I would like to have the comment form display, from top to bottom: 1- the comment-form-comment; 2 - the comment-form-url; 3 - the comment-form-email; 4 - the comment-form-author; 5 - the submit button; 6 - the subscription check-box from a plugin;


According to the 4th reply found in this question: http://ift.tt/18DTXtJ I was able to experiment with these CSS rules:



#commentform {
display:table;
width:100%;
}
.comment-form-comment {
display: table-header-group;
}
.comment-form-author {
display: table-footer-group;
}


but the .comment-form-author ends up below the submit button and the subscription check-box, which is not only not what I need, I also realize I have no clue on how to reorder the middle elements - that would be displaying as table-row-group. Can anyone guide me on how to customize the order of the elements in the comments form?


PS - In case more context can help you guiding me to a different approach: I'm looking to adapt and use the comments form as a form for users to submit content, which I would replace in the posts content with the help of a shortcode plugin. The free versions of the form-building plugins that I found have different limitations and I think the Wordpress comments form might keep more possibilities open, especially when combining it with other plugins.





How can Wordpress be made more memory efficient?


Let's assume this is a site that has dynamic content pertaining to the user, or content that changes very often, so varnish is out. Let's also assume that there are no plugins and the theme is vanilla.


Can Wordpress be tuned so it uses less memory each request? It seems to include all libraries and functions by default. Is it all or nothing, or can it load say the media functions only if it really needs them without being lobotomized?


I was going to ask this on StackOverflow, but I'm pretty sure they would have pointed me here. Maybe ServerFault?





Merge WP_Post and WP_User objects from two separate queries?


I am trying to set up a custom search functionality on a site I am working on. The search currently searches for posts/pages and users based on a set of custom defined user meta.


I have the standard query and the user query stored in variables, but I'm wondering if I can merge the WP_Post and WP_User objects into a single variable to loop over.


If not, how can I go about combining the two terms, so that they appear in the same search results.


This is what I currently have set up



global $wp_query;
$search_term = get_search_query();

$posts = $wp_query->posts;

$args = array(
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'user_nicename',
'value' => sanitize_title( $search_term ),
'compare' => 'LIKE',
),
array(
'key' => 'first_name',
'value' => $search_term,
'compare' => 'LIKE',
),
),
);
$user_meta_search = new WP_User_Query( $args );

$results = $user_meta_search->get_results();

if( !empty( $results ) ) {
$wp_query->posts = array_merge( $results , $wp_query->posts );
}


This currently doesn't loop properly because it's combining WP_Posts and WP_User objects.


Thanks





Content Above the post title, but not on tag or category pages


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


Can you have more than one nonce on a page?


I have a site with a page where there's one form in the sidebar, and one in the main body of the page. The sidebar comes first in the HTML.


Both forms have their own nonces (generated with wp_nonce_field) with different $action and $name parameters. The $referrer fields are on.


When I submit the second form, I get the usual "Are you sure you want to do this?" message.


If I remove the first form, things work correctly.


I added some debugging to wp_verify_nonce (var_dump statements and an exit;) and it's failing after a NULL $nonce and the $action of the first form (i.e. the one I haven't submitted.)


$_POST contains all of the second form, as you'd expect.


Any ideas?





Does is_user_logged_in() block search bots?


I want to use is_user_logged_in() in my home page so users that are not logged in see a sign up page.


I want to know if this function blocks search engine bots from crawling the content inside is_user_logged_in().


If it is blocked; then, how can I allow search engines to crawl the content inside it?





Access the resized images generated by `add_image_size()`


I have set up some shortcodes to make things simpler for the user. It wraps up some bootstrap markup and just lets you put the h1, some img urls, etc in it without getting too close to the markup.


What I originally wanted was to let the user upload the image through the media library and then grab the image url for the resize that I had generated. I thought this used to be in there but I can't find a way.


So assuming thats not possible, is there a way I can take a url such as http://ift.tt/1Dr14Pr which the user will copy paste into the shortcode and then use a WP function to get the url for the columns-thumbnail resize?


If its not built in I can just check the dimensions directly but it feels brittle to do it this way should the size change or the way WP generates filenames change in the future.


Some code:



function roots_setup() {
// snip

// setup image sizes
// http://ift.tt/xBzWPI
add_image_size('triple-thumbnail', 370, 222, true); // true = hard crop
add_image_size('columns-thumbnail', 200, 200, true);

// snip
}
add_action('after_setup_theme', 'roots_setup');

function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'triple-thumbnail' => __( 'Triple Header Image' ),
'columns-thumbnail' => __( 'Columns Thumbnail' )
) );
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );


Shortcode example:



[column imageurl='http://ift.tt/1Dr14Ps' title='Vertical Blinds']


Something that I'm imagining might be in WP already somewhere:



$imageurl = 'http://ift.tt/1Dr14Ps';
$thumbnailurl = WP_get_image_resize_url($imageurl, 'columns-thumbnail');


Does this exist?





How can I remove the Static Front Page option from the Customizer


In Wordpress 4.1's Theme Customizer there's a Static Front Page option. I've set up my theme to have a custom front page (via front-page.php in the theme) so I don't want this option to be available here.


enter image description here


How can I remove it?





Get a List of All Commenters on the Current Post


I'm trying to get a list of everyone who's commented on a post, and then check that list against the current logged in user. If the current logged in user is included in that list, then I don't show the comment form, otherwise they can leave a comment. So essentially, I only want people to be able to comment once per post.


I think I'm close, but I keep pulling in a list of everyone who's commented on any post.


Here's my code:



<?php global $post;
$comments = get_comments($post->ID); // get all comment author emails
foreach($comments as $comment) :
$existingcommenters = $existingcommenters.', '.$comment->comment_author_email;
endforeach;

$current_user = wp_get_current_user(); // then we check those emails against the current users email
$commenting = $current_user->user_email; ?>

<?php $args = array( // i then list my arguments, which I've omitted for clarity here
); ?>

<?php if (strpos($existingcommenters,$commenting) !== false) { // if the user already has a review, don't let them post another ?>
<p>You've already reviewed this business.</p>
<?php } else { comment_form($args); } ?>


So I thought $existingcommenters should only contain a list of people who've commented on this post, as $comments = get_comments($post->ID); should be setting that call to only get a list of comments for this post, right?


If I echo $post->ID anywhere in this code, it does return the current post's ID successfully.


But if I echo $existingcommenters, it shows a list of every single commenter.


Any idea what I might be doing wrong?





How to do a query on custom taxonomies that is uncategorised?


I have a custom taxonomy and I wish to do a query for all custom posts who has no value assigned for that taxonomy (i.e. uncategorised).


This is what I have so far:



$uncatQuery = new WP_Query( array(
'post_type' => 'course',
'tax_query' => array (
array(
'taxonomy' => 'course_category',
'field' => 'name',
'terms' => '',
)
)
) );


However this does not work.


Please help!


NOTE: I manage to get it to work by creating a query to get all tax ids and then use a NOT IN operator, but that requires an additional query.





changed permalink option and get server error


I made a mistake and choose custom permalink option from general settings in dashborad and left the custom field empty and pressed save. Now i have a very cool "500 - internal server error " message on my website. I didn't have a .htaccess file so i made it removed the extension and upload to wordpress directory but no change. What else can i do to fix this problem? Thank you.





Delete thousands of cron jobs


I discovered that I have 29,000 cron jobs in my WordPress database from deactivated and deleted plugins. I have tried a number of optimizer plugins but the huge number of cron jobs means I can't delete them using plugins.


I also tried this in my functions.php without success:



add_action("init", "clear_crons_left");
function clear_crons_left() {
wp_clear_scheduled_hook("cron_name");
}


Is there any SQL command I can use in phpmyadmin to search by cron hook and remove them?





contact form 7 send custom variable to form


My use case is very simple. I have a bunch of books on my site and close to each one there is a button to pop up a "Request Info" contact form to fill.


I'd like that when the user clicks on "Request Info", the email that is sent from CF7 contains the book title too, which I then use into my wpcf7_before_send_mail function.


In other words, if there a way to use a parameter into the CF7 shortcode, so that I can then retrieve it into the before_send function?


Something like:



[contact-form-7 id=1234 title="My form" myvalue="45DC67"]


Thanks


Fabio





Custom url for a single page


Created a page and the link is like the following



http://ift.tt/1Ke67Fk


need to be like the following



http://ift.tt/1CH6gR0


I need this structure only for this page .So i don't want to change the current permalink structure.Is there any other option to achieve this?


Can anyone help please.





Same menu for different taxonomies to reach different content


I'm using a "location" taxonomy to show the same website for 4 different locations. Each of them will have the same categories which I want to display in a menu.


Is there anyway to create the same menu to show posts filtered by category but which also takes into account the current taxonomy the user is in? Can I do it directly using the wordpress panel or would I need to create a specific theme for it?


Basically, the site would have an index with 4 options, for example:



  • London

  • Cambridge

  • Manchester

  • Briton


Once the user click in any of them, a new menu will appear:



  • Cars

  • Tvs

  • Trains

  • Ships


So if I click in first in "Briton" and then in "Cars", the page should only show the posts with the category "cars" which are also inside the taxonomy "Briton".





Is contact form 7 unable to access my uploads folder?


Like I mentioned in a previous question, I want to send an email attachment dynamically when a user gives me there contact details.


I started with the absolute url:



get_template_directory().'/test.pdf'


This works fine, but when I try to reference a file in my uploads folder, it does not work.


Is contact form 7 unable to access my uploads folder?


Okay, so here's my code:



add_action( 'wpcf7_before_send_mail', 'send_pdf' );
function send_pdf( $cf7 ) {
$id = $cf7->id();
if ($cf7->id==1308){
$submission = WPCF7_Submission::get_instance();
$submission->add_uploaded_file('pdf', 'http://ift.tt/1D3JMYG');
}
}


The url here does not want to work, I get an email but no pdf, with the other url though it works fine.


What gives?





Post gallery as carousel


So I have this idea in mind: I would like to create custom page template, and whenever in post gallery is between tags, for example:



Lorem ipsum somethinginkgsd....

[carousel]
Gallery here
[/carousel]


I would like to convert this gallery to a carousel.


Creating carousel is fairly simple I guess. I just need something like get_post_gallery_images, but:



  • get_post_gallery_images will only return first gallery in post

  • this would still render gallery inside a post.


So my question is: how to get exactly the one gallery between [carousel] tags, and how to replace it?


Thank you a lot for any help!





Sudden Sharepress error posting in facebook


Last WP version, up-to-date plugins. I use sharepress plugin to automatically post new entries to some facebook pages.


Suddenly I started to get this error I receive by email and it is in log flie



[Sat Jan 31 07:51:58 2015] [warn] [client: local IP ] mod_fcgid: stderr: SharePress Error: Problem with the SSL CA cert (path? access rights?); while sending --post-name-- --url-post for post 1103, referer: wp-admin/post.php?post=1103&action=edit



No new posts are added to fb.


SSL is not used in this virtual server. Plugin's author says it could be a facebook problem. I don't know where is the origin of the problem.


Log lines before that one are a dozen, exactly the same (time also) as this one



[Sat Jan 31 07:51:34 2015] [warn] [client server's IP ] mod_fcgid: stderr: Problem with the SSL CA cert (path? access rights?)






Save multiple custom post fields from quick edit


Context:


A multiple custom posts and custom fields website. Since the website is rather complex, has a lot of users, a lot of editors and a lot of data, they asked me to allow them to choose which custom fields show up in the quick edit screen for each custom post type. I've managed to add the fields to the quick edit screen and they are all populated with the right values. However,...


The problem:


I don't seem to be able to save the fields from the quick edit menu. Here's the function:



add_action('save_post', 'sb_save_quick_edit_fields');

function sb_save_quick_edit_fields($post_id) {
if (
( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) ||
( !current_user_can( 'edit_post', $post_id ))
) return $post_id;
}

$qef_array = sb_get_qe_fields_options();
/* the function above returns an array from options
* with arrays of custom fields that are added to
* quick edit for each post type, in the form of:
* [
* 'post_type_1_slug' => [
* 'custom_field_1_slug',
* 'custom_field_2_slug'
* ...
* ],
* 'post_type_2_slug' => [...],
* ...
* ]
*/

if ($qef_post_type = $_REQUEST['post_type'])
foreach ($qef_array as $qef_post_type => $qef_fields) {
foreach ($qef_fields as $qef_field) {
if (array_key_exists($qef_field, $_REQUEST))
update_post_meta($post_id, $qef_field, $_REQUEST[$qef_field]);
else
delete_post_meta($post_id, $qef_field);
}
}

}


I don't have a clue about why it's not working. For all I care, it should. Does it have to do with not returning anything? In the examples I found with adding only one custom field to quick edit, the save function returned the custom fields' value upon success, but I can't return, I need to check for the rest of the custom fields. Right?





Block tools menu in wp-admin?


I'm using this code to remove tools from wp-admin menu. But how do I block the access to http://ift.tt/1zjrjIC since I still can visit it by typing in the URL?



add_action( 'admin_menu', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
remove_menu_page('tools.php');
}




RSS Feed Sticky Post?


My latest RSS feed shows 20 posts for example, but I want to include a certain category no matter how old the post is (for example, my 'featured' post category), and also just get 1 latest post from this category.


I've been trying to look for plugins, but I'm not exactly sure what it would be called. Any help would be appreciated.





Pagination breaks custom sub menu


I've got the following class which allows me to make a specific sub menu.



class Custom_Walker_Nav_Sub_Menu extends Walker_Nav_Menu {

var $found_parents = array();

function start_el(&$output, $item, $depth, $args) {

global $wp_query;

//this only works for second level sub navigations
$parent_item_id = 0;

$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

$class_names = $value = '';

$classes = empty( $item->classes ) ? array() : (array) $item->classes;

$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';


if ( ($item->menu_item_parent==0) && (strpos($class_names, 'current-menu-parent')) ) {
$output.= '<li>';
}


// Checks if the current element is in the current selection
if (strpos($class_names, 'current-menu-item')
|| strpos($class_names, 'current-menu-parent')
|| strpos($class_names, 'current-menu-ancestor')
|| (is_array($this->found_parents) && in_array( $item->menu_item_parent, $this->found_parents )) ) {

// Keep track of all selected parents
$this->found_parents[] = $item->ID;

//check if the item_parent matches the current item_parent
if($item->menu_item_parent!=$parent_item_id){

$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';

$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;

$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}


}
}

function end_el(&$output, $item, $depth) {
// Closes only the opened li
if ( is_array($this->found_parents) && in_array( $item->ID, $this->found_parents ) ) {
$output .= "</li>\n";
}
}

function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
// If the sub-menu is empty, strip the opening tag, else closes it
if (substr($output, -22)=="<ul class=\"sub-menu\">\n") {
$output = substr($output, 0, strlen($output)-23);
} else {
$output .= "$indent</ul>\n";
}
}


}


And I use the following function to paginate the posts.



function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}


The problem is, when I click on a page to go, the page loads but the submenu has only one element.This doesn't happen when I go to other main pages such as contact us or any other. What am I doing wrong here since I'm new to wordpress.





Create horizontal login form


I want to create a login form that is horizontal and I don't know how. How can I do this?





Custom Post Types and Pre Populated Custom Taxonomies


I'm building a custom post type that relies on three custom taxonomies. I'm registering all the custom posts and tax... using the init action (this works and I can manage the new aspects)



...
register_taxonomy( 'cppstrands', array( 'cppstatements' ), $args );
...

//Part of the cppmatrix_init method called here
add_action( 'init', 'cppmatrix_init', 0 );
...


I am also trying to prepopulate the tax.. with data when the plugin is activated using register_activation_hook but this fails as Taxonomy does not exist.



...
if(taxonomy_exists('cppstrands')) ...
...

//Part of the cppmatrix_dataInstall called here
register_activation_hook(__FILE__, 'cppmatrix_dataInstall');


I am suspecting that init happens before register_activation_hook but don't know what to do to solve it.


Can anyone help?


Thanks





Woo commerce: After cart page not redirecting to payment gateway


I have a website integrated with pay u payment gateway.after checkout i am not able to redirect on payment gateway page it's redirecting on 404 page.and also not working for any payment gateway like papal and more.


Changes done on site:


before 5 days my site was on Blue Host that time every thing was working good after that we have moved site on ec2-aws linux with bitnami image after the moving site from blue host to ec2-aws i am facing this problem.


I was check the permalink , htacess file but i am not able to trouble shoot what is affecting to redirect on payment gate way.


Bellow details of Product permalink base:-



Custom Base /shop


ht access sample code:-



# 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


Root file structure:-



/opt/bitnami/apps/wordpress/htdocs




Wordpress plugin that snaps picture out of linked site like pinterest?


I was wondering if there is a plugin that automatically snaps out a picture of a linked site, when I am writing a new post and let me use it as a featured image. Pinterest is a very good example for it I guess. greetz :)





how do i embed the pdf gallery in wordpress post


I want to show the epaper of newspaper. Is there a way that i can embed a gallery of pdf in post just like the gallery of images





wordpress custom list table bulk actions


i extended wordpress custom list table class for my plugin. everything works perfectly. Then i want to customize my bulk actions. in bulk action (ie. list table submit) there are 8 POST variable and 1 GET variable. can i include one more post variable with this? i tried with my js file but the var_dump shows the default post and GET variables only. with out this wp-list-table submit i got my custom post and get variables. why this is happened? where this global variables comes from actually?





vendredi 30 janvier 2015

Sort and display pages with specific tag


What I need basically is to display child pages on a parent. But I want to split the list of childs to, lets say, 'important' and 'non-important' to display it at the beginning and at the end of a parent page.


I turned on TAGs for pages in function.php like:



function tags_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
}

// ensure all tags are included in queries
function tags_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
}

// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');


And here's my function and shortcode to display ALL childs on a parent:



function my_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
if ( $childpages ) {
$string = '<ul class="list-in-page-menu">' . $childpages . '</ul><div style="clear:both">';
}
return $string;
}

add_shortcode('my_childpages', 'my_list_child_pages');


But I can't figure out how to sort out child pages with tag 'important' in this function.


Is it possible at all?





Display only posts from referred category on date archive page


I am using wp_get_archive() in category.php.


If I am on page of category=2 it should show my archives of only that category. However it is for all the categories. Following is the code for my category.php as well as archive.php



<?php get_header(); ?>
<?php
$args =array(
'posts_per_page' =>1,
);
$loop = new WP_Query( $args );
if($loop->have_posts()):while ( $loop->have_posts() ): $loop->the_post();
the_content();
endwhile;
endif;
?>
<?php wp_get_archives( array( 'type' => 'daily') ); ?>


First part that is to show archive of specific category was solved by this code thanks to Pieter Goosen - answer given by him on How do I change the sql query for wp_get_archive()


But now problem is that if i go to that archive from the category page, i need to also show only posts from that category only.





Custom Images - Creating Larger Versions


Hey just playing around with the add_image_size for my theme, it works a treat for large images, crops them nicely, however if someone uploads a tiny image, I'm trying to make the size increase or at least crop to the same pixel aspect ration.


Any idea how to make a image increase in size if it is already smaller than the specified parameters set when calling add_image_size function?


Here's my example: add_image_size('mobile-header', '940', '412', true );


Thanks





How do I change the sql query for wp_get_archive()


I am using wp_get_archive() in category.php.


If I am on page of category=2 it should show my archives of only that category. However it is for all the categories.


So how can I change the query for wp_get_archive() that it only redirects to archive template for that specific category

this is the code in my category.php



<?php get_header(); ?>
<?php
$args =array(
'posts_per_page' =>1,
);
$loop = new WP_Query( $args );
if($loop->have_posts()):while ( $loop->have_posts() ): $loop->the_post();
the_content();
endwhile;
endif;
?>
<?php wp_get_archives( array( 'type' => 'daily') ); ?>


and if the same code for archive.php





CDN, SSL, and Kaltura Video Server problem with Wordpress


The current problem weâre experiencing is simply trying to serve the syndicated video over HTTPS. It looks like the JS file on YouniversityTVâs end is currently only configured to serve up HTTP content, and the videoâs themselves also only look to be accessible over HTTP. Iâve tried finagling the video in to an Iframe to get around the mixed content blocking that Chrome implements, but Iâve run in to several hurdles and I think the best/simplest solution would be to make sure that YouniversityTV can properly serve its videos over HTTPS.



http://ift.tt/1yPqdip


Initially we thought it was the CDN setting, but we are lost here. In addition, the https is on address shield is showing. Please contact me if you can fix this.



http://ift.tt/1HvtAWv


Could this be a cause of the video syndication issue? Any help or suggestions will be greatly appropriated.





include statement in index.php does not allow access to $current_user


using a child theme index.php allows access to $current_user


index.php has


include get_template_directory_uri() . '-copy/subPages/account.php';


account.php does not access $current_user and get_currentuserinfo(); inside account.php breaks the include statement





List children of second level sub page


Top Level Page

- Second Level Page

--- Child Page

--- Child Page

--- Child Page


The goal here is to list all children of second level, I have that done from the codex. However, when I click on a Child, the children should still display because we're technically still inside of the Second Level.



<?php
// Globalize the $post variable;
// probably already available in this context, but just in case...
global $post;
wp_list_pages( array(
// Only pages that are children of the current page
'child_of' => $post->ID,
// Only show one level of hierarchy
'depth' => 1
) );
?>




Wordpress editable template fields


I created several template files like this:



<?php
/*
Template Name: My Template 1
*/

get_header('my-template-1');
while ( have_posts() ) : the_post();
the_content();
endwhile;
get_footer('my-template-1');

?>


I can assign a template to each page of my site.


Question:


How can I make specific portions of these templates to be editable in admin?


For example, I wish to have a field (which is assigned to one template) with some specific text in it, and if I edit and save this field - the updated text should appear in all pages that use this specific template.





Creating a one click demo importer


What's the best way of importing demo widget/site options, inside a plugin? I would obviously like to avoid some site options like what the site url is


short of doing a brutal SQL import is there any other way? I would like to incorporate the method into my plugin so that they can click one button for this





WPML. How to connect post translations from frontend form ( or throught php )?


My task is that user should be able to create posts from front-end. I'm using ACF plugin, for creating forms on front-end.


My web is in 2 languages: Rus and Est. User can create on one of that language and than should be able to create a translation to it.


So my question is how to:



  1. Check if there's already translation for these post ( in both directions, if i create first on Rus and i need to check if there's Est translation and if there is - get the id of the post for future needs )

  2. Make it a translation of certain post ( on save post_save ) [ ex. I have post on Rus, now i submited on Est lang. and how to connect them togethere ? ]


Thanks in advance )





WordPress custom post type queries


I'm using custom post types and listing them in single-[customposttype].php?type=example



<?php if (have_posts()) : while(have_posts()) : the_post();the_content(); endwhile; endif; ?>


Now I have 2 different custom post type "customtype1" and "customtype2". "customtype1" is top category for "customtype2". When I add a new post on "customtype2" select category from metabox(I have a selectbox which listed "customtype1" posts.) in "customtype1" list. My question is how can I use a query for listing customtype2 posts which belongs top category page(single-customtype1.php)





Is there a default way in wordpress to create a overlay in the dashboard?


Is there a default way in wordpress to create an overlay in the dashboard area? I need a jquery ui dialog to open after a button click. This is how it goes: The button click will fire a PHP function using AJAX, which in turn will make an API call and the response will be shown in the jquery ui dialog. However, it takes time to receive the response from a remote api server, so I need an overlay with a loader of some kind. Is there anything native to wordpress that I can use? What are my options?





Potential problems with building a plugin having sub modules?


I'm in the process of organizing a lot of different functionality that I had historically written as parts of themes so that I can break the various utilities into plugins.


At this point, I have my list of distinct sets of functionality with each broken down into categories.


Initially, I was planning on writing individual plugins for each distinct set of functionality. However, looking them over, I'm considering building things out by doing the following:




  • Creating a swiss army knife type plugin that houses sub-plugins for most of the generic smaller plugins and providing an admin interface to let the user choose which functionality they want to make use of on their site.




  • Creating a plugin skeleton designed to be used for adding custom taxonomies and post types to a theme which has all of the core code for registering them, adding meta boxes, etc. pre-written and ready to have specifics added.




That being said, I'm looking for input from others on any pitfalls or other things to be aware of about doing this kind of thing.


The swiss army knife style plugin:



  • This will handle initialization, activation, deactivation, and uninstall processes.

  • It will use a namespace so that the code within each plugin can use cleaner names and access other plugins if applicable without having to use the namespace in calls. (obviously the plugin will require at least PHP 5.3, maybe 5.4 if I use traits)


The primary reasons that I'm considering doing this rather than building out separate plugins:



  1. Shared utility code - I tend to use exceptions for all error handling and try to account for various available wordpress debugging tools (WP_DEBUG, etc.) ... and building things out this way should enable me to make improvements in one place rather than having to go through a ton of plugins to change such utility code when I make an optimization.

  2. Ease of Upgrades - I build a reasonable number of sites out each year and it would be nice to be able to offer new functionality by simply updating a single plugin.

  3. Reduced Overhead - If I build out a site that needs 23 different distinct bits of functionality, this would prevent 23 plugins from showing in the dashboard, 23 plugin initializations, etc.


The Custom Taxonomy and Post Type Skeleton Plugin



  • This would be separate as many sites require very distinct capabilities that no other site is likely to want (at least not exactly).

  • The point of the skeleton plugin would be to have all commonly used related code pre-written so that I could create such custom work in a much faster manner.


Thoughts and advice?


I haven't previously went this route with a plugin ( and the swiss army knife style plugin will hopefully be my first plugin to go up on the public repository ) before.


I am looking for any information from others on any concerns with building out something like this so that I can consider them (and hopefully address them) before figuring them out the hard way.


I cannot think of any real drawbacks at this point but realize that I lack experience as a public plugin author and so my question.





Archive filter disappears on no results?


I have been working through this example: http://ift.tt/1yr9ExS


That a colleague of mine found for creating a simple checkbox-based filter for Wordpress custom posts, that filters by a custom post type.


I've got it all set up and it seems to be working here - http://ift.tt/1CYqWlL , if you filter by 'Balcombe Place' then the 'All Locations' post is removed as you would expect.


However if you choose an option that isn't there, the filters disappear on the refresh and I cannot figure out why. My colleague has used this exact code on another site that doesn't have this problem so I'm left stumped. I've tried reordering the elements in the template in case something is affecting it but nothing seems to change.


The code in my archive-jobs.php :



<div class="filterOptions">

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nisl odio, efficitur non lorem ut, volutpat egestas tellus. Vestibulum suscipit sem mi, nec mattis tortor convallis in. Integer in blandit turpis, consectetur tincidunt dolor.</p>

<div id="search-location">
<?php

$field = get_field_object('location_choice');
$values = explode(',', $_GET['location_choice']);

?>
<ul>
<?php foreach( $field['choices'] as $choice_value => $choice_label ): ?>
<li>
<input type="checkbox" value="<?php echo $choice_value; ?>" <?php if( in_array($choice_value, $values) ): ?>checked="checked"<?php endif; ?> /> <?php echo $choice_label; ?></li>
</li>
<?php endforeach; ?>
</ul>
</div>
<script type="text/javascript">
(function($) {

$('#search-location').on('change', 'input[type="checkbox"]', function(){

// vars
var $ul = $(this).closest('ul'),
vals = [];

$ul.find('input:checked').each(function(){

vals.push( $(this).val() );

});

vals = vals.join(",");

window.location.replace('<?php echo home_url('jobs'); ?>?location_choice=' + vals);

console.log( vals );

});

})(jQuery);
</script>
</div>


Code from functions.php:



add_action('pre_get_posts', 'my_pre_get_posts');

function my_pre_get_posts( $query )
{
// validate
if( is_admin() )
{
return;
}

if( !$query->is_main_query() )
{
return;
}

// get original meta query
$meta_query = $query->get('meta_query');

// allow the url to alter the query
// eg: http://ift.tt/WaHaZ0
// eg: http://ift.tt/1xafnZJ
if( !empty($_GET['location_choice']) )
{
$location_choice = explode(',', $_GET['location_choice']);

//Add our meta query to the original meta queries
$meta_query[] = array(
'key' => 'location_choice',
'value' => $location_choice,
'compare' => 'IN',
);
}

// update the meta query args
$query->set('meta_query', $meta_query);

// always return
return;

}


Any help would be much appreciated!





How to set Compatibility Data for MU Plugins


I have pieced together, and believe I understand correctly, that if there is a readme.txt file located in your plugin directory and it contains certain line entries (like "Requires at least:" and "Tested up to:" and "Stable tag:") then compatibility data will show in the Plugin's listing and will not show the message "No compatibility data found".


If my understanding is correct, then how do I set the Compatibility Data for a plugin I made and placed in the mu-plugins directory?


I uploaded a readme.txt file to that directory but nothing happened.





Transient fragments don't seem to work


I am trying to implement transient fragments, I've been doing what is suggested here: http://ift.tt/14uGgEO


Here is my code, in functions.php



function fragment_cache($key, $ttl, $function) {
// getting a custom cache optin value, randomly generated in backend when a user hits "flush cache" button
$cache_version = get_option( 'clear_cache' );
if ( is_user_logged_in() ) {
call_user_func($function);
return;
}
$key = apply_filters('fragment_cache_prefix', 'fragment_cache_').$key.$cache_version;
$output = get_transient($key);
if ( empty($output) ) {
ob_start();
call_user_func($function);
$output = ob_get_clean();
set_transient($key, $output, $ttl);
}
echo $output;
}


And here is my code in my page



<?php while ( have_posts() ) : the_post(); ?>
<?php
fragment_cache('post' . $post->ID, DAY_IN_SECONDS, function() {
include( locate_template( 'partials/related_article.php' ) );
});
?>
<?php endwhile; ?>


where in the include I am just posting a title and an image


My issue is that the code doesn't throw errors, but if I change my article title, I see the new title instead of the cached version. Any idea?





Why are featured images sometimes cropped, and sometimes not


I am developing a website using Wordpress CMS, in particular Hatch theme. I noticed that in some posts, featured image is displayed full size (like here) but in others, featured image has a smaller size, cropping the original image,small featured image enter image description here I don't think it is about image starting size, because some of the images displayed correctly are way bigger than the one it shows as cropped. Both of them are made with cameras. Moreover, if I change the freshly updated photo with another one that i recently uploaded, it shows as cropped, while changing it with older photos shows it full size


Do you know why it behaves like this, and how I can fix it? Can it be an extension issue (even though they both are JPEGs)?


Thanks





Activation Account Email


I use a betnami hosted wordpress multisite, when a user sign up in the site he should receive an email with activation link, but it does not work! so how to make it work? and if it work how to customize the email that the user receive.


Best Regards





Custom url for a single page


Created a page and its link is like the following



http://ift.tt/1Ke67Fk


need to be like the following



http://ift.tt/1CH6gR0


I need this structure only for this page .So i don't want to change the current permalink structure.Is there any other option to achieve this?


Can anyone help please.





Audio or playlist shortcode condition according to the amount of files on attachment page


My reason for doing this is for a music & entertainment site where users will have the ability to share music and videos on other websites via embed code. I'm using the audio.php and video.php attachment pages to load the default MediaElement.js HTML5 Player with all the attached media from it's parent post. I then link to that attachment page via Iframe, thus resulting in a embed code for each audio and video post.


I'm sure a plugin would be much better solution but this is what I can do with my current skill level.


This is what I've gotten thus far.


For the playlist:



<?php
global $post;
$args = array(
'post_parent' => $post->post_parent,
'numberposts' => -1,
'post_status' => 'null',
'post_type' => 'attachment',
'post_mime_type' => array('audio'),
'order' => 'ASC' );

$attachments = get_posts($args);
$medias = $attachments;

if (count($medias) > 0) {
$array = array();
foreach($medias as $media) {
$array[] = $media->ID;
}

$id_comma_separated = implode(',', $array);
echo do_shortcode('[playlist ids="' . $id_comma_separated . '"]');
}
?>


And for single audio.



<?php
global $post;
$args = array(
'post_parent' => $post->post_parent,
'numberposts' => 1,
'post_status' => 'null',
'post_type' => 'attachment',
'post_mime_type' => array('audio'),
'order' => 'ASC' );

$attachments = get_posts($args);
$medias = $attachments;

$medias = wp_get_attachment_url( $attachment_id, 'full' );
echo do_shortcode('[audio src="' . $medias . '"]');
?>


Now obviously this always returns two players no matter what, I need to make this a single query that either executes the [audio] shortcode if only a single audio is available and [playlist] if there is more than one audio attachment in the parent post.


This is as far as I've gotten, everything I tried after this broke the audio attachment page.


I'm a designer not a developer so my PHP skills are very limited, so if there's a better way to do this whole thing, that would be great.


Thanks.





Issue of page width with twenty fourteen theme


I have a site http://ift.tt/1A6nTdx based on Twenty Fourteen theme. I use heavily Mathjax-Latex. For some menus, like Topology, the page width is OK on an iPad.


For other menus like Analysis, the page width is schrinked compared to the width of the screen. This appears only a week before.


Do you have a clue of what can be wrong?


Thanks.





Password protected page Hash url


I am using owl carosel which takes a hash url to go to a specific slide (http://ift.tt/15OZLyL)


Lets say I want to visit a password protected page with the slider there (http://ift.tt/1A6nTdq)


When I visit the page I am asked for a password, upon entering it, the hash at the end is removed after the redirect. (redirects to site.com/page on success)


Any idea where I would look to keep the original url intact?


Just to confirm, there are multiple hash urls so I cannot hard code a single one.


Thanks!





WordPress theme testing tools


I want to test WordPress theme. So which tools can be helpful for me to do it. Its written in php,js,css. I want to do manual testing and automation testing (optional) .





Passing a variable to register_taxonomy()


I'm trying to create multiple taxonomies. As follows.....



$taxonomies = $wpdb->get_results( "SELECT * FROM $table_name" );
foreach ($taxonomies as $taxonomy) {
//stuff that defines the taxonomy
register_taxonomy( $taxonomy->singular_name, 'book', $tagArgs );
}


It appears that WP dislikes regestering the taxonomy with $taxonomy->singular_name. Xdebug givies me the following error.



Notice: Trying to get property of non-object in /home/wpplugin/public_html/wp-includes/link-template.php on line 898


I've tried several diffent things. Converting the object to an array and feeding that to register_taxonomy(), I've tride casting $taxonomy->singular_name as a string and a few other random guessees that yeilded the same result. The only thing that works is putting a quoted string in place of $taxonomy->singular_name which won't fit my needs.


Does any one have any ideas on this?? Thanks Greg


Full code here.....



add_action( 'init', 'create_book_taxonomies', 0 );function create_book_taxonomies() {
global $wpdb;
$table_name = $wpdb->prefix . 'wlc_custom_taxonomy';
$taxonomies = $wpdb->get_results( "SELECT * FROM $table_name" );
foreach ($taxonomies as $taxonomy) {
$enterMeOnce = $taxonomy->singular_name;
$book = $taxonomy->singular_name;

if($taxonomy->singular_name != 'singular-name'){ //exclude the default table row
$resLabels = array(
'name' => _x( $enterMeOnce , 'Post Type General Name' ),
'singular_name' => _x( $enterMeOnce , 'Post Type Singular Name' ),
'menu_name' => __( $enterMeOnce ),
'name_admin_bar' => __( $enterMeOnce ),
'all_items' => __( $enterMeOnce ),
'add_new_item' => __( 'Add New ' . $enterMeOnce ),
'edit_item' => __( 'Edit ' . $enterMeOnce ),
'new_item' => __( 'New ' . $enterMeOnce ),
'view_item' => __( 'View ' . $enterMeOnce ),
'search_item' => __( 'Search ' . $enterMeOnce ),
'not_found' => __( 'No '.$enterMeOnce .' found' ),
'not_found_in_trash' => __( 'No '.$enterMeOnce .' found in trash' ),
'description' => __( $enterMeOnce .' are special posts that are showcased on the '.$enterMeOnce .' page.' ),
);
$resArgs = array(
'labels' => $resLabels,

'public' => true,
'exclude_from_search' => false,
'publcly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-lightbulb',
'capability_type' => 'post',
'meta_box_cb' => true,
'show_admin_column' => true,
'hierarchical' => true,
'has_archive' => true,
//'rewrite' => true,
/*'capabilities' => array(
'manage_terms' => 'manage_resource',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts'
),*/
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'post_format' )
);

register_post_type( $book , $resArgs );

$labels = array(
'name' => _x( $taxonomy->name . ' Categories', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( $taxonomy->name . ' Category', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( $taxonomy->name . ' Categories', 'text_domain' ),
'all_items' => __( 'All Categories', 'text_domain' ),
'parent_item' => __( 'Parent Category', 'text_domain' ),
'parent_item_colon' => __( 'Parent Category:', 'text_domain' ),
'new_item_name' => __( 'New Resource Category', 'text_domain' ),
'add_new_item' => __( 'Add New Resource Category', 'text_domain' ),
'edit_item' => __( 'Edit Category', 'text_domain' ),
'update_item' => __( 'Update Category', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate resource cat names with commas', 'text_domain' ),
'search_items' => __( 'Search Resource Categories', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove resource categories', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used Categories', 'text_domain' ),
'not_found' => __( 'Resource Category Not Found', 'text_domain' ),
'slug' => __( $taxonomy->name . 'category' )
);

$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'rewrite' => true,
);


register_taxonomy( $taxonomy->singular_name, array( $book ), $args );

$tagLabels = array(
'name' => _x( 'Writers', 'taxonomy general name' ),
'singular_name' => _x( 'Writer', 'taxonomy singular name' ),
'search_items' => __( 'Search Writers' ),
'popular_items' => __( 'Popular Writers' ),
'all_items' => __( 'All Writers' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Writer' ),
'update_item' => __( 'Update Writer' ),
'add_new_item' => __( 'Add New Writer' ),
'new_item_name' => __( 'New Writer Name' ),
'separate_items_with_commas' => __( 'Separate writers with commas' ),
'add_or_remove_items' => __( 'Add or remove writers' ),
'choose_from_most_used' => __( 'Choose from the most used writers' ),
'not_found' => __( 'No writers found.' ),
'menu_name' => __( $taxonomy->name . ' Tags' ),
);

$tagArgs = array(
'hierarchical' => false,
'labels' => $tagLabels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'writer' ),
);

register_taxonomy( $taxonomy->singular_name, $book, $tagArgs );


}
}
}




Highlight specific menu item when custom post is page


I know that this question was asked many times, but I did not find a really good solution for my problem:


I have a custom post type "event" with some categories like "lecture". For each category, I created an individual page which shows category infos and a list of the events from this category. The pages are all accessible from submenu entrys.


If I open an event, no menu item is highlighted as current. I think the best solution would be to "link" each category to it's page, but I don'T know how to do this.


Adding the proper classes to the menu items and and their parents would be good, but modifying the nav menu walker would be perfect (another addon nneeds to know which one is the current menu entry to show the current submenu in a second navbar).





Search tags in CPTs


I can't seem to figure out how to include tags in a wordpress search. For example, if I search for 'apple', I would like to get back posts with 'apple' in the title or the content (default wordpress functionality) as well as posts that contain the tag 'apple'; When I add the 'tag' => $keyword line into WP_query then I get no results for every search.



$keyword = get_search_query();
$args = array(
'post_type' => array('case_studies', 'news', 'events'),
'post_status' => 'publish',
's' => $keyword,
'tag' => $keyword,
);
$query = new WP_Query($args);


If I remove it, I get results as normal (but without posts with the keyword in its tags)





How to show full image like as its uploaded to the frontend of the product page?


Recently, i have uploaded one large product image as featured image and i can see full image into the featured image area but at the front end of this product page i can see crop version of that image into the my main product image and i can't see the side of my product image.


visit to this link: http://ift.tt/1JTty8u


Anyone could tell me that how to show the exactly same featured image as i can see at the backend of my product page to the fronend of my main product image instead of the crop version of that image?





Display sub categories and their data of a taxonomy


I want to output the sub category details of a taxonomy



$getTerms = get_terms($taxonomy, $args);
print_r($getTerms);


When i print the above out it returns the object. But theres no value difference between parent and sub categories. The first is a parent taxonomy and the second is a sub-category.



[1] => stdClass Object
(
[term_id] => 23
[name] => Corporate teams
[slug] => corporate-teams
[term_group] => 0
[term_taxonomy_id] => 23
[taxonomy] => team_names
[description] => Description of corporate team
[parent] => 0
[count] => 0
[image_id] => 0
)

[3] => stdClass Object
(
[term_id] => 25
[name] => Team name 1
[slug] => team-name-1
[term_group] => 0
[term_taxonomy_id] => 25
[taxonomy] => team_names
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec pellentesque sapien.
[parent] => 22
[count] => 1
[image_id] => 90
)


How would i query part of this object (likely as a foreach or as a WP_Query) so it will return the sub categories and their relavant values (title, image,etc)? Is the 'get_terms()' function the right way to go for this?





Hosting Problem. Don't know which to chose


Can any one tell me:



  1. About 35,000 Visitors Per day and 100,000 plus page views per day

  2. About 1.5 Million visitors per month and about 2/3 Million page views.


which hosting to chose ?? and which should i chose i mean should a chose share hosting or VPS Hosting or Dedicated Hosting ? Please leave a reply Thanks





Include attachments with a custom taxonomy in search


I need to include attachments in the search. So far, I have managed this by hooking into pre_get_posts and checking if it's on the search results page, I add 'attachment' to the post_type and 'inherit' to the post_status, in order to also include attachments that are not attached to posts.


However, only attachments that have the custom taxonomy download_category set to any term should be included, attachments that do not have any download_category may not be seen in the search results.


How can I achieve that?


I have found this answer Custom Taxonomy WP_Query for All Terms in a Taxonomy? and tried it out. While this does really only show those attachments with any download_category set, it applies to posts and pages as well, and as those never have the download_category taxonomy set, no pages and posts are shown in the search results...


So to clarify again what I need in short terms: - include attachments in the search results, but only if they have taxonomy download_category set to any term - Keep normal search functionality for pages and posts!





File path for attachments outside of wp-content/uploads


I am creating some custom post creation pages with PHP.


I create a simple post and want to attach an image I already have on my server to the post without moving it into the upload directory. I am trying to do it this way.



$post=array(
'post_content'=>$body,//
'post_title'=>$title,//
'post_status'=>"publish",//
'post_author'=>1,//
'post_category'=>Array($category),//
);

$newPostID = wp_insert_post($post,$wp_error);

$attachment = array(
'guid' => $imageURL,
'post_mime_type' => $filetype['type'],
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $imageURL ) ),
'post_content' => '',
'post_status' => 'inherit'
);
print_r($attachment);
$attach_id = wp_insert_attachment($attachment, $imageURL, $newPostID);
set_post_thumbnail($newPostID,$attach_id);


Where $imageURL is the path to my image file.


When I do this and check the Media Library, there is an entry for this file, but for its URL, it has my upload directory prefixed to $imageURL. Like http://domain/uploads/http://domain/myRealImageFolder


Is there away to achieve what I want without copying the file into the upload folder?





Custom template of page with blog posts list for multi-blog page


I need to use (on my theme) multi blog pages (Posts page). My idea is using page template for it, but I have a problem with getting all posts in template file. Regular loop the_post() from index.php file does not work.


I created blog-template.php file based on http://ift.tt/1orySJr idea and code of my file looks:



/*
Template Name: Blog (Posts page)
*/

$args = array( 'post_type' => 'post' );
$post_list = new WP_Query( $args );

while ( $post_list->have_posts() ) {
$post_list->the_post();
get_template_part( 'templates/content', get_post_format() );
}


but I think.. it is not perfect solution to use WP_Query(). Is it possible to do it better? and mark my blog-template.php file as a special file with Blogposts in order to the_post() function works?


regards


Marcin from Poland





How to change the sql query to show date archive of that particular category


I am using wp_get_archive() in category.php.


If I am on page of category=2 it should show my archives of only that category. However it is for all the categories. Following is the code for my category.php as well as archive.php



<?php get_header(); ?>
<?php
$args =array(
'posts_per_page' =>1,
);
$loop = new WP_Query( $args );
if($loop->have_posts()):while ( $loop->have_posts() ): $loop->the_post();
the_content();
endwhile;
endif;
?>
<?php wp_get_archives( array( 'type' => 'daily') ); ?>


First part that is to show archive of specific category was solved by this code thanks to Pieter Goosen - answer given by him on How do I change the sql query for wp_get_archive()


But now problem is that if i go to that archive from the category page, i need to also show only posts from that category only..


Please help me out





Wordpress showing images as a broken icon


Ok. So what i did is that I've Followed this http://ift.tt/1CX6QJZ


Click here! After using this trick the website is showing broken symbol in place of the newly uploaded Images. The old uploaded images are working fine.





Best way to display multiple pdfs?


I am building a WP page that links to multiple PDFs. I am looking for the best way to display it such that it is fast to load and not too tacky (like the PDF viewer).


For now, I am building a carousel of thumbnails and each of them link directly to the PDF. Because it links to the PDF, the website is pretty much disappear. It makes it bad for user flow and look and feel. For example, the user has to click Back to go back to the website.


The solution I like is that it is thumbnails of articles and a canvas within the website. Whenever you click on the thumbnails, it will load the article into the canvas.


The problem with PDF is that it requires a PDF viewer. Which it looks awful and slow to load.


Does anyone know a plug-ins that can help me out with this?


I am playing around with Easy FancyBox and PageFlip5


Thanks! Cliff





Display problem with list-category-post 0.55


I started managing a Wordpress 4.1 site http://ift.tt/1JSqFom hosted by 1&1 running Travelify theme. I used the same data to run a Wordpress site locally on a MacBookPro. Both use plugin list-category-post to display posts. Before upgrading to list-category-post 0.55, both display category posts without excerpts. After upgrading, both display category posts with excerpts. The code shows



'excerpt' => 'no',


What do I need to do to display category posts without excerpts using list-category-post 0.55? Is there a way to revert back to a previous version?


Cheers, Luby





How to clone wp-admin and make a new dashboard controlled by your code?


Let's say I want to create a new admin panel for WordPress. Which should be separate from the one we have now. How do you think I should start?


I want to build /wp-admin/ from scratch for administrators. Which means, the new admin panel should have everything /wp-admin/ has. Why need to build a new panel? Because the present one keeps changing, and what I am upto needs an area which is under my control, and not changed by every WP update, but I update it when I want to.


Summary: I want to build root.com/dashboard/ which has everything present at root.com/wp-admin/


How do you propose I begin? What is necessary to make a completely new WordPress admin panel work. Which files, permissions, sessions etc I should be looking at. Looking forward to some pointers from you guys.





jeudi 29 janvier 2015

Why is this coming back as null? Thats wrong. There is one post


I have a category, called events. It is assigned to one post. So I created the following loop:



$args = array ('category_name' => 'events', 'posts_per_page' => 4, 'order_by' => 'date', 'order' => 'DESC' );
$category_posts = new WP_Query($args);

if ($category_posts->have_posts()) {
while ($category_posts->have_posts()) {
$category_posts->the_post();
var_dump($category_posts->the_post());

?>
<div class="col-md-6">
<?php $category_posts->the_post_thumbnail(array('class' => 'events-image')); ?>
</div>
<div class="col-md-6">
<h4><?php echo $category_posts->the_title(); ?></h4>
<span class="date"><?php echo date('M j, Y', $category_posts->get_the_date()); ?></span>
<p><?php echo implode(' ', array_slice(str_word_count($category_posts->the_content(), 2), 0,120)); ?> [...]</p>
</div>
<?php
}
}


Notice the var_dump($category_posts->the_post()); it comes into here and does this var_dump but the Output is NULL. wtf?


Whats confusing is it has posts, its get into the while statement but the $category_posts->the_post() is null? This makes little to no sense at all.





Sort and display pages with specific tag


What I need basically is to display child pages on a parent. But I want to split the list of childs to, lets say, 'important' and 'non-important' to display it at the beginning and at the end of a parent page.


I turned on TAGs for pages in function.php like:



function tags_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
}

// ensure all tags are included in queries
function tags_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
}

// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');


And here's my function and shortcode to display ALL childs on a parent:



function my_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
if ( $childpages ) {
$string = '<ul class="list-in-page-menu">' . $childpages . '</ul><div style="clear:both">';
}
return $string;
}

add_shortcode('my_childpages', 'my_list_child_pages');


But I can't figure out how to sort out child pages with tag 'important' in this function.


Is it possible at all?





Troubleshooting MySQL Wordpress


In the process of trying to install iDevAffiliate and creating a new database, I messed up my existing WordPress database. I'm not even sure what I did, but I'm now getting some WordPress errors that point to database problems.


One error is that the Membermouse plugin reports: "Currently MemberMouse can't utilize the cache." A related problem is that when I attempt to update a plugin, Wordpress now takes me to a page that says "To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host." Finally, when I attempt to upload an image to the media library, I get this message: "The uploaded file could not be moved to wp-content/uploads/2014/11." I have no idea why it's trying to move it to 2014/11 when it should be uploading to 2015/01.


At first, I thought these were problems with the directory permissions, which I had also changed while trying to create the idevaffiliate directory in the same directory as wp-content, wp-admin, etc. But the directories are all set to 755 now, and that didn't make any difference.


So how do I do basic trouble-shooting steps with MySQL and WordPress? I'm running a LEMP stack on Amazon EC2, so I Putty in and would love to get the Linux commands to do such things as check to see that the database credentials in wp-config.php is still allowing access to the database, or what else might be wrong.


I'll owe you a free membership at CoolHotNot.com (and more) if you help me fix this! Thanks.





Create navigation link to existing Wordpress page


I have this blog. If you see the example post on the front page it says that it is posted in Blog. As you can see this is the blog page that will list all of the blog posts, yet this page is not listed in the main navigation. How do I add this page and make it go to the blog page instead of creating a blank page?





Posts side by side on single page


i am new on wordpress. i want to show 4 different posts in 4 columns on a home page. Kindly help me. Thanks.





Get the advantages of low Roti creating device price


When it comes to creating chapati, it always informs of creating it typically in Indian, which has been an difficult and long procedure. Planning all the money and then pushing it is very difficult but then investing more here we are at food preparation Chapati on a hot green is really an distressing experience. The scenario becomes really crucial at locations where chapatis are required in large amount. With the progression in technological innovation, man power has decreased to a higher extent; the food market has found an substitute to generate Roti or chapatis in large amounts. The developing of Automatic Chapati Making Machine is really a great innovation and also the low Chapati Making Device Cost In Indian has made this machine available for everyone and has decreased the life of individuals in the kitchen.



With an automated chapati creating machine you will ignore the complications of creating chapati and will enjoy creating it. It is an electronically run automated machine which makes chapatis in big amounts in a lowest period of your energy and effort. This huge stainless-steel machine contains 2 parts- one aspect creating the money paintballs in equivalent dimension and another aspect clicks the money paintballs switching them into chapatis and then lastly food preparation them. Roughly 1000 chapatis are created by the roti creating machine in an time. Due to cost-effective Roti Making Device Cost In Indian different sections of community such as platform food preparation areas, assisted living facilities, hostels, huge commercial canteens and many more have started purchasing this machine that is assisting them at a higher level.



There are many benefits of Its main benefit is that as in comparison to conventional way of creating roti the automated roti creating machine is completely sanitary. No human contact is required as the device does almost all the perform. Only an owner is required just to over look at the development procedure and observe the device studying. Another benefits is that all the chapatis will be of equivalent dimension and also equally cooked. The machine is set to a certain heat range that it makes all the chapatis in appropriate way from both ends. It is simply the cost-effective method of generating chapatis in variety without limiting on high quality.



The roti creating devices are developed to convenience perform, while still allowing individuals to make clean chapatis. If you think of purchasing this machine then you can perspective the Chapati Making Machine Cost on internet and then buy the top high quality machine from a well-known producer.






How wordpress plugin hooks works?


I am new to wordpress development. I am familiar with joomla's ins-and-out working mechanish, now i want to contribute or say learn wordpress. I found that every thing in wordpress is done through plugin and its hooks and filters. But before diving into writing some cool stuffs, i want to know how hooks registered in plugin executes ? which design patterns is implemented in wordpress plugin environment ?


OK, lets take example.



add_action( 'wp_head', 'my_plg_function' );
function my_plg_function() {
echo 'I am called';
}


In above code, plugin's function is registered in wp_head hook, right ? Now what exactly does add_action function does and when wp_head hook runs, how my plugins function called ? Again I am new to this, i am trying to learn and create cool stuffs in wordpress. Any helps will be appreciated. Thanks





Why am I getting posts back when I shouldnt


I have the the following variables being populated:



$posts = wp_get_recent_posts(array (
'numberposts' => 4,
'post_status' => 'publish'
));

$categoryPosts = wp_get_recent_posts(array (
'numberposts' => 4,
'category' => get_cat_ID('events'),
'post_status' => 'publish'
));


Now posts should have 1 post, the default sample hello world post. The second should be an empty an array, as this category has 0 posts associated with it.


Instead I get back (twice):



array(24) { ["ID"]=> int(1) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2015-01-28 20:49:24" ["post_date_gmt"]=> string(19) "2015-01-28 20:49:24" ["post_content"]=> string(130) "Welcome to demosite network. This is your first post. Edit or delete it, then start blogging!" ["post_title"]=> string(12) "Hello world!" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(11) "hello-world" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-01-28 20:49:24" ["post_modified_gmt"]=> string(19) "2015-01-28 20:49:24" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(49) "http://ift.tt/1ET0P0L" ["menu_order"]=> int(0) ["post_type"]=> string(4) "post" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "1" ["filter"]=> string(3) "raw" }


I get it back twice because I have two loops that loop over both arrays and var dump out the array.


My question is: For the $categoryPosts array Why am I getting the above array back? I should get nothing correct?





How to show category images (from plugin) on a regular page (page-example.php)?


I am trying to use the Category Images Plugin to show images with my Custom Taxonomy (Region) categories/terms. Here is the code I have so far in a page-example.php that lists all the categories/terms with their descriptions:



$siteurl = home_url('/');
$tax = 'region'; // slug of taxonomy

$terms = get_terms($tax);
foreach ($terms as $term) {
$slug = $term->slug;
$description = $term->description;
$link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>";

echo $link;
echo '<p>' . $description . '</p>';
}


The documentation for the Category Images Plugin says "Use [the function] to get the url and put it in any img tag in category or taxonomy template.


Is it possible to get the image urls in my existing code even though it's a regular page and not a category or taxonomy template file?


Any help or direction would be much appreciated as I'm not sure where to even start.





wordpress database error


I write code to extract peice from website with curl. this should be refresh page to get price.


I want store data in the wordpress database with foreach.


when I refreshing page


but give this error.



Call to a member function insert() on a non-object in C:\wamp\www\wordpress\wp-content\plugins\price\fras-coin.php on line 73



database



foreach($table_rows as $tr) { // foreach row
$row = $tr->childNodes;
if($row->item(0)->tagName != 'tblhead') { // avoid headers
$data[] = array(
$trip ['Name' ]= trim($row->item(0)->nodeValue),
$trip['LivePrice'] = trim($row->item(2)->nodeValue),
$trip ['Changing']= trim($row->item(4)->nodeValue),
$trip ['Lowest']= trim($row->item(6)->nodeValue),
$trip['Topest']= trim($row->item(8)->nodeValue),
$trip['Time']= trim($row->item(10)->nodeValue),

);
}
}
global $wpdb;
foreach($table_rows as $tr) { // foreach row
$row = $tr->childNodes;
if($row->item(0)->tagName != 'tblhead') { // avoid headers
$wpdb->insert( $wpdb->farsc,
array(
'title' => " . trim($row->item(0)->nodeValue) . ",
'liveprice' => " . trim($row->item(2)->nodeValue) . ",
'changing' => " . trim($row->item(4)->nodeValue) . ",
'lowest' => " . trim($row->item(6)->nodeValue) . ",
'topest' => " . trim($row->item(8)->nodeValue) . ",
'time' => " . trim($row->item(10)->nodeValue) . " ),
array(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
) );
///$sql = "INSERT INTO `fars_coin`(title,liveprice,changing,lowest,topest,time) VALUES ('" . trim($row->item(0)->nodeValue) . "','" . trim($row->item(2)->nodeValue) . "','" . trim($row->item(4)->nodeValue) . "','" . trim($row->item(6)->nodeValue) . "','" . trim($row->item(8)->nodeValue) . "','" . trim($row->item(10)->nodeValue) . "')";
///
///mysql_query($sql);

}


}





Wordpress install becomes unresponsive


I feel like I am taking crazy pills. I did a Wordpress install as a favour and set it up using Nginx and php5-fpm with microcaching. I followed the wordpress.org instructions and when I finished I tested the install with ab and hit it with 100,000 requests with a concurrency of 100. The site worked fine and responded to my browser request while getting hit by ab.


Now a couple days later the site is completely unresponsive: Nginx responds with a 504 Gateway Time-out. And I see very strange requests in the error logs.


A representative Nginx log entry looks like this:



173.245.52.82 - - [30/Jan/2015:05:11:51 +0000] "GET /blob HTTP/1.1" 301 5 "-" "WordPress/4.2-alpha-31287; http://example.com"


That IP address is a Cloudflare address which is not unsurprising since I put this install behind Cloudflare. And the log is just full of entries exactly like this over and over and over. I then restart php5-fpm and get four requests in quick succession and then it seems like it stops responding.


What is going on? I noticed this similar behaviour and thought maybe it was a bad plugin or theme, but I moved the blog over to a fresh install of WP this began again.