lundi 20 avril 2015

How to add a meta box for categories in Wordpress?

I want to add two meta boxes for categories, so that I can add additional content or information to each of my categories.

In the template of the categories I will then read the contents of those meta boxes, but how can I add meta boxes to categories? I can only see documentation for doing this on pages and posts or custom post types, but categories?

Error in plugin for WooCommerce

I have recently started writing a plugin for the woocommerce, and everything worked flawlessly before I tried to hook the extension to the system.

I have a following code inside my class.

function add_gateway($methods)
{
  $methods[]  = 'Rentalbloom_WSPay';
  return $methods;
}
add_filter('woocommerce_payment_gateways', 'add_gateway');

Class has constructor defined as a public function __contruct() so it shouldn't have problems with the access, but when I try to run this I get the following error.

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION and the error points to the add_filter line written above.

I don't know if this is relevant, but I'm using a PHP version 5.3 on the APMPPS stack on the OS X.

How to add location url in Wordpress(Appearance --> Menu --> URL)?

I'm working on WP site which is currently having this kind of testing instace url: http://someipaddress/~directory/directory/ and then "wp-admin"

now If I want to link of any page in top navigation through wp-admin--> Appearance --> Menu

I need to use "/~directory/directory/" in URL field(THIS IS WHAT THE PROBLEM IS)

/~directory/directory/
Now I've to move it on production instance, and it has different kind of url like : "http://mywpsite.com/", so again I need to change this URL over there.

Does anyone has any idea how to tackle this?

Adding post with thumbnail image to Wordpress blog with JoeBlogs / C#

I'm trying to add new post with thumb image but i still couldnt get success on it.

 public static int addContent(int postType, string title, string body, string post_thumbnail, string[] categories, string[] tags, DateTime dateCreated)
{
  Post post = setPost(postType, title, body, post_thumbnail, categories, tags, dateCreated);
  using (var wrapper = getWordPressWrapper())
  {
    return wrapper.NewPost(post, true);
  }
}

get setPost method,

public static Post setPost(int postType, string title, string body, string post_thumbnail, string[] categories, string[] tags, DateTime dateCreated)
{
  string type = postType == 1 ? "post" : "page";
  var customFields = new CustomField[] { 
    new CustomField() { 
        // Don't pass in ID. It's auto assigned for new custom fields.
        // ID = "name", 
        Key = "post_thumbnail", 
        Value = post_thumbnail
    } 
    //,
    //     new CustomField() { 
    //    // Don't pass in ID. It's auto assigned for new custom fields.
    //    // ID = "name", 
    //    Key = "post-thumbnail", 
    //    Value = post_thumbnail
    //}  ,
    //     new CustomField() { 
    //    // Don't pass in ID. It's auto assigned for new custom fields.
    //    // ID = "name", 
    //    Key = "post-thumbnails", 
    //    Value = post_thumbnail
    //} ,
    //     new CustomField() { 
    //    // Don't pass in ID. It's auto assigned for new custom fields.
    //    // ID = "name", 
    //    Key = "thumbnail", 
    //    Value = post_thumbnail
    //} 
  };
  return new Post
  {
    PostType = type,
    Title = title,
    Body = body,
    Categories = categories,
    Tags = tags,
    DateCreated = dateCreated,
    CustomFields = customFields
  };
}

as you see its commented. I tried everything to post thumb images.

I've tried post_thumbnail, post-thumbnail, post-thumbnails, thumbnail keys but nothing happen.

How can i do that?

Get Woocommerce customer order language

I'm developing a complementary plugin for woocommerce. I have a sql request that gets all the order and customer info, but i need to get the language from the order.

How can i detect the language was using a customer when he made an order? Is it registered somewhere?

In other CMS like prestashop it's stored as id_lang in orders and customer tables.

Sorry for my English.

Thanks in advance!

WP: wp_list_pages different sort_column for depths

I'm using wp_list_pages to generate a custom menu for certain pages and it works as expected.

I was wondering if it's possible to use 'sort_column' parameter based on depth, so that first-level pages (top parent pages) are sorted by let's say 'menu_order' and other level pages are sorted using 'post_title'.

By reading codex I didn't find what I was looking at. Will I need to use walker to achieve this? If so, I would be glad if I could get some tips on this.

Thanks

Wordpress Frontend Ajax with wp_localize_script Error: ajaxurl is not defined

I'm trying to create markers on a map via ajax on a wp theme. After some struggle I found out that I can't use any php file to get data via ajax, I have to use the admin-ajax.php file.

Accordingly to many examples, this is my code

in functions.php

add_action( 'wp_enqueue_scripts', 'add_frontend_ajax_javascript_file' );
function add_frontend_ajax_javascript_file()
{
   wp_localize_script( 'frontend_ajax', 'frontendajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
    wp_enqueue_script( 'ajax_custom_script',  get_stylesheet_directory_uri() . '/includes/ajax-javascript.js', array('jquery') );

}

add_action( 'wp_ajax_get_post_information', 'get_post_information' );
add_action( 'wp_ajax_nopriv_get_post_information', 'get_post_information' );


function get_post_information() 
{ 

$get_this= $_GET['this'];
$get_that= $_GET['that'];

...my select...

echo json formatted data
}

The js file is loaded and working, it does other stuff before the ajax call, where it stops for an error in this line:

$.post({ 
        url:frontendajax.ajaxurl,
        {
            action: 'get_post_information',
            data: data
        },
        success: function(response) {

But I always Have the same error:

Reference Error: frontendajax.ajaxurl is not defined

where is my error?

PS: I use get_stylesheet_directory_uri() because I am in a child theme.