Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

mae48 on "limit search for specific category"

$
0
0

I tried this code in my search.php
<?php
if( is_search() ) :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("s=$s&paged=$paged&cat=-71,-6,-69,-68,-73,-75,-74");
endif;
?>

but it didn't work....I am using slug on each categories..How can I work on this for it to be functional?


justplaindoug on "WP CLI in Python?"

$
0
0

I wrote a bash script to run wp cli commands automatically. However I need to run it on a windows server, so I can't run bash. So I was thinking python.

Except, I don't know much about python. Could anyone get me started?

or, is there a better way? I've already asked and my ops teams doesn't want to install win-bash or any other program to run bash scripts on windows servers.

yiselwordpress on "I need load more post any idea of what can I do?"

$
0
0

I need load more post, I installed two plugins, "Load More" and "Easy Load More", but don't worked for me, Now I need any idea for load more post by my own way, I'm pretty new in wordpress, thanks

Mr. Default Gravatar on "One in the widgets equals two 's in the site body"

$
0
0

Hi!

I'm using a child theme of twenty twelve.

I'm using a Poll plugin (WP-Polls if that plays a role, but don't think so) and I have the poll displayed in a widget in the sidebar, as well as on a page called "Polls Archive".

The plugin uses the same template for the poll displayed in the widget, as on the site body / main div.

I wanted to add a
to make a space between the "Vote" button and one of the answers of the poll. I thought it was all too narrow, when in the widget. But on the "Polls Archive" page, which is basically just a normal Wordpress page, the space was there already. So when I added my
, it seemed as there were two spaces (or two
s) on the "Polls Archive" page. But now it looked good in the widget.

Does anyone know how I can fix or reset this, so it's the same settings on both? What parameters do I need to overwrite?

All help is seriously appreciated. :)

gfdfgdfg6666444 on "SELL CVV GOOD FULL US UK (ICQ 6665-64689) CA AU EU - DUMPS TRACK"

$
0
0

Contact my ICQ on Tilte for business

WanderlustShutter on "how to use wp dropdown users instead of login in wp login form"

$
0
0

Hello

I would like to use wp_dropdown_users as login in wp_login_form. Any ideas how to combine those two functions?

matnfneo on "Know JS handlers."

$
0
0

Hi, how are you?

I'm trying to enqueue all my js, to see if that improve my load speed.

When I try to get each handler with these lines in the functions.php (I don't kwno another way):

function head_scripts_handle() {
global $wp_scripts;
foreach( $wp_scripts->queue as $handle ) :
echo $handle,' ';
endforeach;
}
add_action( 'wp_print_scripts', 'head_scripts_handle' );

I only get some handlers, about 23, and if I go to the source code of my site I see 32 js.

There is a way to get all the handlers? And for example:

JS Handle
script.js script handle

So, I will have the script X belong to the handler X (there are a few scripts that I can't identify the handler).

Thanks in advance!

enriquerene on "Edit my plugin page"


Bas Schuiling on "Private plugin update renames directory since 4.4"

$
0
0

I'm using a plugin that comes from a self-hosted site which pushes the plugin update information via the plugins_api filter.

Since WP 4.4. a new update results in renaming the directory. Previously this was (example) : '/my-plugin/plugin.php', but now some sort of hash is added, which results in something like '/my-plugin-IB4Ya7/plugin.php' .

The latter part of the name is random and changes every update. I pushed the same update multiple times and every time it's a different string ( same length and composition though ).

I'm browsing the source to figure out what's causing this and why. While annoying it provides no direct problems but I would like to understand if this is a bug or a feature.

Anybody can give me some pointers to this, or have seen this happen on other (commercial) plugins? The plugins coming from WordPress.org repository don't have this behavior.

I maintain the site where the plugin comes from as well. I've checked the information it pushes but it's up to documentation ( the little there is ), and this doesn't happen in WP 4.3 with the same update and code.

MACscr on "CPT's and proper permalinks"

$
0
0

Ok, so I have written my own custom post type plugin that also includes its own custom taxonomy (pretty much just categories that are specific to the CPT. Anyway, I cant for the life of me figure out how to get a permalink of domain.com/cpt-name/custom-taxonomy/postname/. Ive found some old solutions, but they all seem like really dirty hacks and are probably outdated. What is the proper and offical way of doing this? I of course already have the basic rewrite enabled for the cpt and taxonomy.

ageorgiev on "How to add pricing to post (via PayPal)?"

$
0
0

I am currently developing a very simple system. Custom Post Type with a front-end form and an option to make this post "premium" when you pay extra fee. The form works great, but the Paypal button does not. How should I integrate it?

function front_end_form() {

	?>
	<form id="custom-post-type" name="custom-post-type" method="post" action="">

<p><label for="title">Title</label><br />

<input type="text" id="title" value="" tabindex="1" size="20" name="title" />

</p>

<p><label for="description">Short Description</label><br />

<textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea>

</p>

<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>

<input type="hidden" name="post-type" id="post-type" value="appnotifications" />

<input type="hidden" name="action" value="appnotifications" />

<?php wp_nonce_field( 'name_of_my_action','notifications_field' ); ?>

</form>
	<?php

	if($_POST){
		ty_save_post_data();
	}

}
add_shortcode('notification','front_end_form');

function ty_save_post_data() {

	if ( empty($_POST) || !wp_verify_nonce($_POST['notifications_field'],'name_of_my_action') )
	{
	   print 'Sorry, your nonce did not verify.';
	   exit;

	} else{

		// Do some minor form validation to make sure there is content
		if (isset ($_POST['title'])) {
			$title =  $_POST['title'];
		} else {
			echo 'Please enter a title';
			exit;
		}
		if (isset ($_POST['description'])) {
			$description = $_POST['description'];
		} else {
			echo 'Please enter the content';
			exit;
		}

		// Add the content of the form to $post as an array
		$post = array(
		'post_title' => wp_strip_all_tags( $title ),
		'post_content' => $description,
		'post_category' => $_POST['cat'],
		'post_status' => 'publish',
		'post_type' => $_POST['post-type']
		);
		wp_insert_post($post);

		$location = home_url();
        echo "<meta http-equiv='refresh' content='0;url=$location' />"; exit;
	}

}

Stefan M. on "Pre- / Post Upgrade Hooks/Actions"

$
0
0

I do filechecks on each wordpress installation which scans files with a cronjob 1 per week and report all changes.

I would like to automatically make following process.
When update of theme, code or plugins is triggered (automatically or manual):

  • First run filecheck $xxx->filecheck('report=yes');
  • Do Updates as normal
  • Run Filecheck again with $xxx->filecheck('report=no');

For that I'm looking for the apropriate hooks / Actions to use.

I did find those:

  • pre_set_site_transient_update_plugins
  • upgrader_post_install

But I think, that the first one is not a correct one.

Does anyone know the correct hooks to use for this?

Thanks for the help and Regards

Stefan

perthmetro on "Converting a date format from a custom field"

$
0
0

I've looked at these 2 solutions but they are not working for me?
date-time-last is my custom field...

<?php $date = get_post_meta('date-time-last'); echo date('l jS F Y', strtotime($date)); ?>
http://wordpress.stackexchange.com/questions/12031/converting-custom-field-date-format

<?php $date = get_post_meta('date-time-last'); echo date('F j, Y', strtotime($date)); ?>
https://wordpress.org/support/topic/converting-a-date-format-from-a-custom-field?replies=6

In both cases the date I get is always January 1, 1970

gesichtssalat on "list videos instead of image-thumbs"

$
0
0

Hey Guys,

I'm trying to modify this loop (from page-blog.php), in order to scan for - and display embedded videos (such as YouTube or Vimeo).
It is searching for images by default and lists their thumbnails.

Instead of this, I need the loop to check for embedded videos, that then should be directly listed - not just their thumbnail.

Any ideas? Thanks a lot in advance!

<?php
global $wp_query;
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; }

	$args = array(
		'post_type' => array('post','image'),
		'post_status' => 'publish',
		'orderby' => 'date',
		'order' => 'DESC',
		'paged' => $paged
	);
	$wp_query = new WP_Query($args);

	while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

		// IF AN EMBEDDED YOUTUBE OR VIMEO VIDEO HAS BEEN FOUND,
		// PLACE THE VIDEO (INSTEAD OF A THUMBNAIL) WITHIN THE BLOG-LIST
		// ELSE...

			<?php echo the_post_thumbnail('blog'); ?>

		// THIS WILL BE THE SAME FOR BOTH CASES (VIDEO OR IMAGE)

		<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
        <p><?php echo get_the_excerpt(); ?></p>

	<?php endwhile; ?>

samperet on "Putting post title into link for form tracking"


mae48 on "Calling data to database"

$
0
0

I have this addon in my plugin...And I customize one of the functionalities of it..My problem is that, I can't connect my date to my own table...Can someone send me the correct syntax??
Here is my code:
jQuery( document ).ready( function(){

var data_id = 2;
var data_id_2 = 3;

var format = 'mm-dd-yy';
jQuery( 'fieldset[data-id="' + data_id + '"] input' ).datepicker({ dateFormat: format });
jQuery( 'fieldset[data-id="' + data_id_2 + '"] input' ).datepicker({ dateFormat: format });
});

Korvapuusti on "Plugin with Ajax and cURL"

$
0
0

Hi,

I apologize for the very long entry but I'm a bit a loss with plugin creation.
I'm trying to code a plugin for internal use. It should offer a widget where the user can choose a source language, a target language and a text to translate; these info are then sent (in ajax) to a translation program hosted on a thrid-party server (hence the cURL part) and, finally, the translated text is displayed in the widget, below the text to translate.

I was able to do the form, cURL and ajax with two php files, and a mix of php, html and js so that it works but translating this into a plugin (and even worse, in a plugin with a widget) was a totaly different story and I'm not a developper...

I've tried to correctly implement Ajax in the WordPress way but I'm not sure if it is ok like that and I actually don't know how I could make the widget display my code ^^° I guess I should put something in the function widget ? (but then what ?)

Below, the php code :

<?php
/**
Plugin Name: Moduletrad
Plugin URI:
Description: Plugin to interface automatic translation
Version: 1.0
Author: Korvapuusti
Author URI:
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: traduction-ipra
*/

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

define(plugin_dir_path(__FILE__));
define(plugin_dir_url(__FILE__));

// enqueue the js script
function plugintrad_enqueuescripts(){
	wp_register_script ('ajax-script', plugin_dir_url(__FILE__) . '/js/ajax-script.js', array( 'jquery' ),'1',true);
	wp_enqueue_script('ajax-script');
}

// passing the url of admin-ajx.php
wp_localize_script( 'ajax-script', 'ajax-script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );

add_action('wp_enqueue_scripts', plugintrad_enqueuescripts);

// form to send source language, target language and the text to translate
// text area to receive the translated text
function plugintrad_form(){
	?>
	<form method="post" action="" id="form">
		<label for="source">Langue source</label>
			<select id="source" name="source">
				<option value="fr">Français</option>
				<option value="en" selected="selected">Anglais</option>
				<option value="ar">Arabe</option>
			</select>

		<label for="target">Langue cible</label>
			<select id="target" name="target">
				<option value="fr">Français</option>
				<option value="en">Anglais</option>
				<option value="ar">Arabe</option>
			</select>

		<p>
		<label for="textatrad">Saisissez le texte à traduire</label>
		<br />
		<textarea name="textatrad" id="textatrad" rows="10" cols="50" maxlength ="255"></textarea>
		</p>

		</form>
		<div>
			<textarea name="traduction" id="rep" rows="10" cols="50"></textarea>
		</div>
	<?php
} ?>

<?php // function to handle the info obtained with the form (url-ification, sending to the server hosting the translation program, retrieving the translated text)
function moduletrad_ajax_handler (){
	$params = array(
		'q' => urlencode(htmlspecialchars($_POST["q"])),
		'key' => "bla",
		'target' => $_POST["target"],
		'source' => $_POST["source"],
		);

	function httpPost($url,$params){
	$postData = '';
   //crée les paires nom-valeur séparées par &
   foreach($params as $k => $v)
   {
      $postData .= $k . '='.$v.'&';
   }
   $postData = rtrim($postData, '&'); //enlève le dernier & pour que la fin de l'url soit correcte
   $proxy = "172.20.12.74";
   $proxyport = "3128";

   $link = $url .'?'. $postData;
   //curl
	$ch = curl_init(); // initialise la session curl

	// réglage des options curl
	curl_setopt($ch,CURLOPT_URL,$link); // url à récupérer
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); // return la réponse du serveur
	/*curl_setopt($ch,CURLOPT_HEADER,false); // n'inclue pas l'en-tête dans la valeur de retour*/
	curl_setopt($ch,CURLOPT_PROXY, $proxy);
	curl_setopt($ch,CURLOPT_PROXYPORT, $proxyport);
	curl_setopt($cURL,CURLOPT_HTTPHEADER,array (
        "Content-type: application/json",
		"Accept: application/json"
    ));

	$output = curl_exec($ch);

	curl_close($ch); // ferme la session curl
	return trim($output);
}

$data = httpPost("http://adress.domain:0000/translate", $params);
$data = json_decode($data, true);
echo $data['data']['translations'][0]['translatedText'];
}

//creating Ajax call for WordPress
add_action('wp_ajax_nopriv_moduletrad_ajax_handler','moduletrad_ajax_handler');
add_action('wp_ajax_moduletrad_ajax_handler','moduletrad_ajax_handler');

// adding the widget
add_action('widgets_init','moduletrad_init');

function moduletrad_init(){
	register_widget("moduletrad_widget");
}

class moduletrad_widget extends WP_widget{

	function moduletrad_widget(){
		$widget_ops = array(
		'classname'		=> 'traduction',
		'description'	=> 'Automatic translation of specific terms'
		);
		parent::__construct('widget-moduletrad','Widget de traduction', $widget_ops);
	}

	function widget($args,$instance){
		extract($args);
		echo $before_widget;
		echo $before_title.$instance["titre"].$after_title;
		echo $after_widget;
	}

	function update($new,$old){
		return $new;
	}

	function form($instance){
	?>
	<p>
		<label for="<?php echo $this->get_field_id("titre"); ?>">Titre :</label>
		<input value="<?php echo $instance["titre"]; ?>" name="<?php echo $this->get_field_name("titre"); ?>" id="<?php echo $this->get_field_id("titre"); ?>" type="text"/>
	</p>
	<?php
	}
} 	?>

and the js (ajax-script.js):

$(document).ready(function($){
			$("#rep").hide();
			$("#textatrad").on('input', function(){
				var textatrad = $("#textatrad").val();
				var source = $("#source option:selected").val();
				var target = $("#target option:selected").val();

				if (source == target){
					alert("la langue source et la langue cible doivent être différentes");
				}
				else if (textatrad == ""){
					$("#rep").hide();
				}
				else {
					$.post("ajaxtraitement2.php", {q: textatrad, source: source, target: target},
					url : ajax-script.ajaxurl,
					rep : {action: "ajaxscript"},
					function (data){
					$("#rep").show().empty().append(data);
					}
				)}

			return false;
			});

		});

`
At this point, any advise would be most welcomed...

Advanced SEO on "How to compress original image during upload?"

$
0
0

WordPress will compress scaled thumbnails of picture during upload, but, original image will be is same quality.

I am trying to compress original image too. I wish to make image in original resolution available for users, but to compress it and save disk space. For example original 16 MP, hi resolution image can be 5 MB, but after applying 85% compression filter it can be 2-3 MB without noticeable quality loss.

Also I need to preserve image EXIF data.

Solution (need tweak):

This function will compress original photo too, but it will strip EXIF/IPTC data too.

function wt_handle_upload_callback( $data ) {
    $image_quality = 85; // 85% commpresion of original image
    $file_path = $data['file'];
    $image = false;

    switch ( $data['type'] ) {
        case 'image/jpeg': {
            $image = imagecreatefromjpeg( $file_path );
            imagejpeg( $image, $file_path, $image_quality );
            break;
        }

        case 'image/png': {
            $image = imagecreatefrompng( $file_path );
            imagepng( $image, $file_path, $image_quality );
            break;
        }

        case 'image/gif': {
            // No 'image quality' option
            break;
        }
    }

    return $data;
}
add_filter( 'wp_handle_upload', 'wt_handle_upload_callback' )

How to preserve EXIF data, and to compress original image?

mae48 on "metadata database"

$
0
0

Hi, I want to output all the information I stored to my rate table wp database...
how can I do that using this code...??
Or am I doing it right?Thanks

// add the settings under ‘General’ sub-menu
add_action( 'woocommerce_product_options_general_product_data', 'ayg_add_custom_settings' );
function ayg_add_custom_settings() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Create dropdown for via
woocommerce_wp_select(
array(
'id' => 'ayg_via',
'label' => __( 'Via', 'woocommerce' ),
'required' => false,
'clear' => false,
'type' => 'select',
'options' => array(
'option_a' => __('cebu', 'woocommerce' ),
'option_b' => __('clark', 'woocommerce' ),
'option_c' => __('davao', 'woocommerce' ),
'option_d' => __('Iloilo', 'woocommerce' ),
'option_d' => __('Manila', 'woocommerce' )
)));

echo '</div>';
// Create location
woocommerce_wp_text_input(
array(
'id' => 'ayg_location',
'label' => __('location', 'woocommerce'),
'desc_tip' =>'true',
'description' =>__('Enter location','woocommerce')
));
// Create Hotel name
woocommerce_wp_text_input(
array(
'id' => 'ayg_hotel',
'label' => __('hotel', 'woocommerce')
));
woocommerce_wp_text_input(
array(
'id' => 'ayg_hotel_price',
'label' => __('hotel price', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
));
woocommerce_wp_text_input(
array(
'id' => 'ayg_mark_up',
'label' => __('Mark Up', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
));

}
add_action( 'woocommerce_process_product_meta', 'ayg_save_custom_settings' );
function ayg_save_custom_settings( $post_id ){
//via
$woocommerce_via = $_POST['ayg_via'];
if( !empty( $woocommerce_via ) )
update_post_meta( $post_id, 'ayg_via', esc_attr( $woocommerce_via ) );
// location
$woocommerce_location = $_POST['ayg_location'];
if( !empty( $woocommerce_location ) )
update_post_meta( $post_id, 'ayg_location', esc_attr( $woocommerce_location ) );
// hotel name
$woocommerce_hotel = $_POST['ayg_hotel'];
if( !empty( $woocommerce_hotel ) )
update_post_meta( $post_id, 'ayg_hotel', esc_attr( $woocommerce_hotel ) );
// hotel price
$woocommerce_hotel_price = $_POST['ayg_hotel_price'];
if( !empty( $woocommerce_hotel_price ) )
update_post_meta( $post_id, 'ayg_hotel_price', esc_attr( $woocommerce_hotel_price ) );
// Mark Up
$woocommerce_markup = $_POST['ayg_mark_up'];
if( !empty( $woocommerce_markup ) )
update_post_meta( $post_id, 'ayg_mark_up', esc_attr( $woocommerce_markup ) );
add_action( 'woocommerce_product_write_panel_tabs', 'woo_add_custom_admin_product_tab' );
}

john0799 on "How Do I remove The sitename from all page titles ?"

$
0
0

After switching to a new different WordPress theme, Google started adding the sitename to all my pages in the search results. Even when leaving the sitename area blank , Google adds the Homepage title next to every page title. example "Page Title - Sitename" or "page title - homepage title". I only want the Page title to show.

Currently I am using the yoast seo plugin and tried removing removing "%%sep%% %%sitename%%" in the yoast settings, but it didnt work.

Please help

Viewing all 8245 articles
Browse latest View live




Latest Images