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.

Wordpress not installing index.html

I am trying to install a theme, but all the files in the theme are of .html extension. Due to which wordpress is not accepting index.html, I changed it to index.php, it was installed successfully this time, but the style was not applied. Can anyone help me how to solve this issue.

Wordpress Open Social Error:"Strict Standards: Only variables should be passed by reference"

I am using the Open Social Plugin in Wordpress. I also installed the Debug Plugin to see what is going on. I get a PHP Error saying:

Strict Standards: Only variables should be passed by reference in /wp-content/plugins/open-social/open-social.php on line 111.

Line 111 in open-social.php:

'google'=>"http://ift.tt/1IwJpbJ".(isset($_SESSION['WPLANG_LOCALE'])?$_SESSION['WPLANG_LOCALE']:'en_US')."&sl=zh-CN&tl=".(isset($_SESSION['WPLANG_LOCALE'])?reset(str_split($_SESSION['WPLANG_LOCALE'],2)):'en')."&u=%URL%"

Does anyone know what is wrong with this line? I am stuck here.

How get posts from a subcategory of a category by name?

I'm trying to create a subcategory template of a defined category. For example, for each one, I would like to check if his subcategory Photos exists and to get posts of this.

Here is my category tree:

— Category Sessions
— — Subcategory Session 2015
— — — Subcategory Photos
— — — Subcategory ...
— — — Subcategory Videos
— — Subcategory Session 2014
— — — Subcategory Scores
— — Subcategory Session 2013
— — — Subcategory Photos
— — — Subcategory ...
— — — Subcategory Videos

If subcategory Photos of this session category exists :

My idea is to have a query such as :

$wp_query = new WP_query(... Session 20XX/Photos ...&showposts=20);

Is there a way to do that please?

Insert query not working for non-logged in user in wordpress

I am trying to create a function for count post views. for this i have added code in my function file.

Here is my code:

function processpost_views( ){
        global $user_ID, $post;
        if( is_int( $post ) ) {
            $post = get_post( $post );
        }
    if( !wp_is_post_revision( $post ) )
    {
        if( is_single() || is_page() )
        {
            $id = intval( $post->ID );
            global $post;

            $date = explode('-', date('W-d-m-Y', current_time('timestamp')));
                foreach (array(
                0 => $date[3].$date[2].$date[1],    // day like 20140324
                1 => $date[3].$date[0],             // week like 201439
                2 => $date[3].$date[2],             // month like 201405
                3 => $date[3],                      // year like 2014
                4 => 'total'                        // total views
                ) as $type => $period)
                {
                insertView($post->ID, $type, $period, 1);
                }
        }
    }

}

second function

function insertView( $id, $type, $period, $count = 1 ) {

    global $wpdb;
        $wpdb->postviews = "{$wpdb->prefix}postviews";
        $wpdb->test = "{$wpdb->prefix}test";
        $count = (int) $count;      

        if ( ! $count ) {
            $count = 1;
        }
        $sql = $wpdb->prepare("
                INSERT INTO " . $wpdb->prefix . "postviews (id, type, period, count)
                VALUES (%d, %d, %s, %d)
                ON DUPLICATE KEY UPDATE count = count + %d",
                $id,
                $type,
                $period,
                $count,
                $count
            );      

        $wpdb->query($sql);


}

add_action( 'wp_head', 'processpost_views' );

In this above code, my insert and update queries work i am logged in but when i am guest/ logged user this code not work. Please help me.

my message in admin bar in wordpress

Creating my wp 4.2 plugin I make check if dependable plugins are installed. The question is I would like to show error in admin bar, but did not find how to make it. Can be better decision ?

Thanks!

How can I make this code work in css?

I have this page

http://ift.tt/1Hnia4O

right column passed as you can see below.

This is because this code

.theme-page-wrapper.right-layout .theme-content, 
.theme-page-wrapper.left-layout .theme-content {
    width: 90% !important; //This should be the 73%
}

I only want 70% value on this page and I tried this code

body.page.page-id-7674.theme-page-wrapper.right-layout .theme-content, 
.theme-page-wrapper.left-layout .theme-content {
    width: 73% !important;
}

Unfortunately this code is not working and can not understand why. Can you please help me solve this problem?

Thanks in advance!

WordPress - If Category selected = ?, display?

Currently, I am displaying all of my posts in a list, which works fine, as below:

    <div class="container">
  <div class="row" style="margin-top:20px;">
    <?php 
    $args = new WP_Query();
    $loop = new WP_Query( $args );
    while ($loop->have_posts() ) : $loop->the_post();
    ?>
    <div class="col-md-8 col-sm-12 col-xs-12">
      <div class="postsize">
      <div style="float: left; padding-right:20px;">
        <?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>
      </div>
      <h5 class="captext"><?php the_title(); ?></h5>
      <span class="entry-date-orange"><?php echo get_the_date(); ?></span>
      <p style="margin-top:10px";><?php the_excerpt(); ?></p>
    </div>
  </div>
  <?php endwhile; ?>
  <?php wp_reset_query(); ?> 


</div>
</div>

What I need, is options on the right hand side, which shows all my post categories. Once a post category is selected, the list of posts is recalculated and displays only the posts from the selected categories.

So for example, I would have the below layout:

POST CATEGORY LIST

POST

POST

POST

POST

POST

And once a selected post category is selected, the list on the right changes.

Any ideas? Thank you.

Redirection loop on activating https on cloudflare enabled wordpress site

I've a Wordpress site (with latest version). The site was running properly until I've activated force https from cloudflare! Cloudflare now a days provides free ssl and google also likes SSL enabled sites. That's why I've activated SSL from cloudflare and added page rule in cloudflare to force https.

I've also changed site's base url and home page url with https, but it still having redirection loop.

I don't have any idea if I'm supposed to post my personal site's URLs here or not. If required I will post the URL.

Can anyone help please.

Failure to login in Car park Booking plugin in wordpress [on hold]

I purchase WordPress plugin name "car park booking" its working fine but after 1 year it stop working.Now its admin panel can not login if i give wrong email and password then show error but if i give correct email and password then it redirect same page.

I am using woocommerce-composite-products (plugin). i want to Apply component-level discounts over sale prices?

In woocommerce-composite-products (plugin) i want apply discount based on sales price. by default it calculate by regular price.

as per woo documentation I can use filter woocommerce_composited_product_discount_from_regular. my code is below

add_filter( 'woocommerce_composited_product_discount_from_regular', 'wc_cp_composited_product_discount_from_regular', 10, 3 );


function wc_cp_composited_product_discount_from_regular( $from_regular, $component_id, $composite_id ) {
return false;
}

I tired to add this code in plugin and add in wp theme but it working.

can anyone help me ?

W3 total cache cdn url not working with theme

I am currently trying to integrate W3 Total Cache to a wordpress website and i have noticed some rather weird behavior with the CDN url request being sent.

I am currently using s3/cloudfront and i have my CNAME (cdn.example.com) pointing to the cloudfront url.

Now all the images, css and javascript that are not part of the theme are rendering properly with the CDN CNAME url.

example: http://ift.tt/1JlNEXI
http://ift.tt/1yJU42H
http://ift.tt/1JlNEXL

(May I also add that this also happens with the cloudfront url as well.) But when it come to the css and javascript that are part of the woo theme it renders as follows.

http://ift.tt/1yJU42I
http://ift.tt/1JlNEXM

I have taken this up with the theme developers and others concerned but very little has come out from them.

I have looked at various options like using preg_replace to match the occurrence of the weird url and replace it with an empty string.

This however did not work because i was probably using/calling the wrong add_action or add_filter from the reference documentation http://ift.tt/1yJU42L and that of wordpress (I mean wp_head or wp_footer).

As you may have figured out I am not experienced with wordpress and I ask that you please help explain what is going on or wrong with this and possible ways i can resolve this matter.

Thanks for your help.

How to use jquery in WordPress page

How could I make this code to work in a WordPress page?

<!DOCTYPE html>
<html>
<head>
<script src="http://ift.tt/1xDNnh9"></script>

<script>

jQuery(document).ready(function($) {
    $("a").click(function(){

        $('#versie').text('Welkom '+ $(this).attr('data-name'));
    });
});
</script>

</head>

<body>

<div id="div1"><h2>Selecteer de gewenste versie: <span id="versie"></span></h2></div>

<a href="#" data-name="2007">2007</a> | <a data-name="2010" href="#">2010</a> | <a data-name="2013" href="#">2013</a>  

</body>
</html>

i translate my site into arabic so i need to change (ALL) to arabic word [on hold]

i need to change the word ALL to another word how? when u make many pages at the main page or any link you will get 1 2 3 4 pages and all to show the all pics or show the full info at the page so if i need to change the word of ALl to another word how to do it?