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

mannyotr on "Dynamically Add Dropdown Values"

$
0
0

I currently have a child page with a custom form. The form has two dropdown fields. The values on the second dropdown have to be dynamically populated based on the selection of the first dropdown.

After much research and trials, I have come up with a solution that is ALMOST there, but not quite complete.

Currently I have this javascript in my header...

<script>

  function removeAllOptions(selectbox)
  {
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
      selectbox.remove(i);
    }
  }

  function addOption(selectbox, value, text )
  {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;

    selectbox.options.add(optn);
  }

  function SelectCategory(){

    removeAllOptions(document.drop_list.category);
    addOption(document.drop_list.category, "", "Category...", "");

    if(document.drop_list.Category.value == 'Fruits'){
      addOption(document.drop_list.category,"Mango", "Mango");
      addOption(document.drop_list.category,"Banana", "Banana");
      addOption(document.drop_list.category,"Orange", "Orange");
    }
    if(document.drop_list.Category.value == 'Games'){
      addOption(document.drop_list.category,"Cricket", "Cricket");
      addOption(document.drop_list.category,"Football", "Football");
      addOption(document.drop_list.category,"Polo", "Polo", "");
    }
    if(document.drop_list.Category.value == 'Scripts'){
      addOption(document.drop_list.category,"PHP", "PHP");
      addOption(document.drop_list.category,"ASP", "ASP");
      addOption(document.drop_list.category,"Perl", "Perl");
    }

  }

</script>

In the content of my child page I have this code to generate the first dropdown:

<select name="race" onChange="SelectCategory();">
  <option value="Fruits">Fruits</option>";
  <option value="Games">Games</option>";
  <option value="Scripts">Scripts</option>";
</select>

The 'option' lines above are actually being generated from a MySQL query call. But that is not important here.

This is the code for my second dropdown:

<select id="category" name="category">
  <option value="">Category...</option>
</select>

Right now the code actually works as is. The second dropdown is populated with the values in the SelectCategory function based on the value selected on the first dropdown.

The problem is that right now the values in the function SelectCategory are hardcoded (as you can see). I really need the addOption line values in that function to be generated from a MySQL query that is based on the value selected in the first dropdown.

So if a user selects 'Games', I need to run a query that selects all games. That list would then be passed to the function in order to add the list of games to the second dropdown.

I am having a hard time figuring out how to make that happen.

Please help!

Manny


M.Danz on "Query only returning 1 result"

$
0
0

I'm using woocommerce and i'm attempting my own custom query. What i want to be returned is the top categories by sales. For example if the category(taxonomy) ship has 64 sales, car has 45 sales & boat has 23 sales. Then what should be returned is ship, car & boat in that order. Here is my attempt at the query:

global $wpdb;

    $result = $wpdb->get_results ( "SELECT wp_term_taxonomy.taxonomy, sum(v1.meta_value) FROM wp_posts
    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
    INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
    INNER JOIN wp_postmeta v1 ON (wp_posts.ID = v1.post_id) AND v1.meta_key='total_sales'
    WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'product' AND wp_term_taxonomy.taxonomy = 'product_cat'
    GROUP BY wp_term_taxonomy.taxonomy
    ORDER BY sum(v1.meta_value) DESC
 " );

print_r($result);

Here is the query not in wordpress format:

SELECT category, sum(sales)
FROM table
GROUP BY category
ORDER BY sum(sales) DESC

How do i solve this? I only get 1 result in the array when it should return multiple results, where did i go wrong?

Sarief on "woocommerce - difference between _price and _regular_price"

$
0
0

working on plugin to auto update price of product using xml of another website.

I've found two meta_key's but which is more appropriate? which should I use? why are there two?
Does anyone knows the difference?

urstrulychitra on "Youtube Thumbnail not appearing in Wordpress homepage"

$
0
0

Hi this is my blog homepage http://vijaykumar.host22.com/

And this http://vijaykumar.host22.com/?p=8 is the post which i have posted my video

In post there is no problem of video i mean it is appearing....

But in my homepage it is not playing iam getting frustrated with this iam new to wordpress any plugin need to add this or any code need to add this thanks in advance step by step procedure needed in solving this iam new to wordpress....

outkax on "wp_update_user problem"

$
0
0

I am trying to make a profil.php page that will allow users to access their profiles either integrated into the design. So I have my file that works well for backup usermeta it well in db and puts me in the corresponding fields. I would like to allow the user to change his password and / or email, website on the same page as the wordpress user page.
My code is as follows in the head:

<?php
$user = wp_get_current_user();
if($user->ID == 0){
    header('location:/dogepress');
}
if(!empty($_POST)){
    update_user_meta(get_current_user_id(),'scrypt',$_POST['scrypt']);
    update_user_meta(get_current_user_id(),'sha256',$_POST['sha256']);
}
$user_id=$current_user->ID;
$user = wp_update_user(array(
'ID' => $user_id,
'user_email' => $d['user_email'],
'first_name' => $d['user_first_name'],
'last_name' => $d['user_last_name'],
'display_name' => $d['user_display_name'],
'user_url' => $d['user_url'],
));

?>

and the code in html is:

<label for="user_url">Website:</label>
<input type="text" value="<?php echo isset($current_user->user_url) ? ($current_user->user_url ): ''; ?>" name="user_url" id="user_url">
`
Can you help me

dbhynds on "Trouble saving settings on options page"

$
0
0

I'm having trouble saving settings. I think I've got everything set up correctly, but when I click "Save Changes," it says "Settings saved" but doesn't actually update anything in the database. What am I doing wrong. I feel like it's something obvious.

By the way, the way I'm doing it is setting up an associative array of setting groups ($setting_groups) with settings in them and looping through it to add and register settings.

Here's my code:

<?php
var $setting_groups = array(
	'lazyloadxt-general' => array(
			'title' => 'General Settings',
			'settings' => array(
				'lazyloadxt_min' => array('Minimize Scripts','checkbox'),
				'lazyloadxt_extra' => array('Extras','checkbox'),
			)
		),
	);

function __construct() {
	if ( is_admin() ){
		add_action( 'admin_menu', array($this,'admin_menu') );
		add_action( 'admin_init', array($this,'register_settings') );
	}
}
function admin_menu() {
	add_options_page('Lazy Load XT Settings', 'Lazy Load XT', 'administrator','lazyloadxt',array($this,'settings_page'));
}

function register_settings() {
	$setting_groups = $this->setting_groups;
	foreach ($setting_groups as $group => $settings) {
		add_settings_section(
	        $group,         // ID used to identify this section and with which to register options
	        $settings['title'],                  // Title to be displayed on the administration page
	        array($this,'settings_section_callback'), // Callback used to render the description of the section
	        'lazyloadxt'                           // Page on which to add this section of options
	    );
		foreach ($settings['settings'] as $setting => $setting_args) {
			register_setting('lazyloadxt',$setting);
			add_settings_field (
				$setting,
				$setting_args[0],
				array($this,'form_field'),
				'lazyloadxt',
				$group,
				array(
					'id' => $setting,
					'type' => $setting_args[1]
				)
			);
		}
	}
}

function settings_section_callback($args) {
}

function form_field($args) {
	if ($args['type'] == 'checkbox') {
		$val = (get_option($args['id'])) ? 'checked="checked' : '';
		echo '<input type="checkbox" value="1" '.$val.' />';
	}
}

function settings_page() {
    ?>
    <div class="wrap">
        <?php screen_icon(); ?>
        <h2>Lazy Load XT Settings</h2>
        <form method="post" action="options.php">
        <?php
            // This prints out all hidden setting fields
            settings_fields( 'lazyloadxt' );
            do_settings_sections( 'lazyloadxt' );
            submit_button();
        ?>
        </form>
    </div>
    <?php
}

monkey201311 on "Youtube video in query"

$
0
0

I have posted a standard youtube link on a page. It displays this specific video on a page.

Is there a way to call a specific youtube video from outside of Wordpress, to play in Wordpress site without having to create every single videos in a different posts?

Jose81 on "korean letters not shown in Plugin Mapplic"

$
0
0

Hi there,

I need to display korean characters on my website. On the website itself it is working well. But on the Plugin Mapplic it is not. When I write Korean on the Plugin, the characters are displayed fine. But after saving it, instead of the Korean letters question marks appear.

I contacted the developer of Mapplic already and he suggested me to change the collation of the plugin in my MySql database of the plugin to utf_8. I tried that with several collations, for instance utf8mb4_general_ci (which is used by the theme, which can display Korean characters), utf8_general_ci or euckr_korean_ci. It still didn't work out, even after rewriting the content.

I know I should ask this question to the developer of Mapplic, but sadly he is not responding fast (he usually needs more than 1 week to reply), which is why I hope somebody here in the forum can help me out.

Thanks


makably on "Sql Injection In Wordpress Is Possible ?"

$
0
0

I Want To Know Whether All My Wordpress Sites Are Safe From SQL Injection....
So, Is It Possible That Wordpress Sites Can Be Hacked By SQL Injection ?
Do Let Me Know....

If Yes, Then What Are Methods To Stay Safe ?

Thanks

edtiley on "Why does $_REQUEST work but not $_POST"

$
0
0

I'm building an OOP plugin to create admin pages to be used by a Multisite superadmin that uses a custom table. It's a simple routine. Pick a record from a dropdown list, then get all the field data and display a second form to edit those fields.

Since there seems to be no way to call a class method in the action = part of the form tag, I've written a function that uses action = '' so the page will call itself on submit. The method is POST

Here's the logic:

if($_POST['form_two'] !== 'save_data' ){
   global $wpdb ;
   //do a query, get some values create a form to
   // let the user select one from a dropdown
   echo '<form type="post" action="" id="select_one" name "select_one">';
   // a foreach to populate and display the <select> element
   echo '<input type="hidden" name="form_two" id="form_two" value="save_data"/>';
   echo '<input name="send_select" id="send_select" type="submit" value="Select Ad To Edit" />';
   echo '</form>';
} else {
// the code for the edit form
}

Fails every time. But change _POST to $_REQUEST and it works perfectly. You get an ungainly URL when you use REQUEST, which seems a bit odd too, but it works great.

I just want to know why $_POST doesn't get populated but $_REQUEST does. It took me a LONG LONG time to figure out this hack. I' just like to gain a little knowlege for the effort.

Thanks,

Ed

salamanderX on "why need init_settings()"

$
0
0

Hi,

Im creating a Woocommerce payment gateway plugin and I see in lots of other plugs that the constructor also calls for the method init_settings()
$this->init_settings();

Why is this needed? My settings are displayed with init_form_fields() and saved with process_admin_options action. So why is the init_settings needed and what does it do?

Thank you,
S.

motoDrizzt on "Adding submenu to frontend navigation menu"

$
0
0

Hi all.

I'm developing a plug-in, and one of the things I need is to be able to build and entire navigation menu from scratch.

Up to now I've been able to use wp_create_nav_menu to create a navigation menu, retrieve it when needed with wp_get_nav_menu_object, and add and modify first level menu items with wp_update_nav_menu_item.

Problem I'm facing now, I've got not the palest idea how to add a sub menu to the first level item I've created. I was thinking that calling wp_update_nav_menu_item with the first level menu item as parent would have worked, but it doesn't.

Example:
I create a nav menu. It' term_id is 600;
Then I create a menu item with wp_update_nav_menu_item: it works, and newly created menu item has ID 602
Now I want to add a child to menu item 602, but if I call wp_update_nav_menu_item with 602 as first parameter it gives error; checking function code, it seems it fails on trying to check if my menu item is a nav menu, which obviously it isn't.

What I'm supposed to do, then?

clairative on "unknown conflict"

$
0
0

please help me.
there is something in my wordpress (I think a jquery) that creates a conflict with almost all plugins. the problem is that when the pages are opened from the menu of the blog do not work, but if you do a refresh of the browser everything works fine.
I do not know where and what to look for, someone has an idea?

shecodes on "Built-in Gallery Function Limitations?"

$
0
0

I haven't found a gallery plugin that I feel comfortable using for a responsive solution, they all seem to suck on mobile. So I have tried to customise and style the built-in gallery and combine it with a gallery custom post type. Which works providing -

a) you upload images directly into and specifically for use in one particular gallery
- if they are attached elsewhere, the gallery thumb links to the attachment page, but won't link it to the other images on the same gallery using a navigation function, nor will it link back to the gallery but back to the original attachment page or post instead elsewhere within the website.

b) caution if adding new images to an existing gallery
- won't necessarily link the images together when you click through from the thumbnail and then use previous_image_link or next_image_link. The new images will go back to the gallery but not link to next or previous images contained within the gallery.

If the above is correct (a) I can work around, but (b) does need sorting if it's possible.
Here is the code used to navigate between images via the attachment pages (thumbnails are linked to attachment) I've 'borrowed' from the TwentyFifteen theme. -

<div id="gallery-navigation" class="navigation image-navigation golf-link">

     <?php
        // close button back to gallery thumbnails.
        the_post_navigation( array(
            'prev_text' => _x( '<span>Close</span>', 'Parent post link', 'dvgc-responsive' ),
        ) );
     ?>

    <div id="image-navigation" class="navigation image-navigation golf-link">

        <div class="nav-previous-img">
                <?php previous_image_link( false, __( '&Lt; Prev', 'dvgc-responsive' ) ); ?>
        </div>

        <div class="nav-next-img">
                <?php next_image_link( false, __( 'Next &Gt;', 'dvgc-responsive' ) ); ?>
        </div>

    </div>

</div>

I am also using the new RICG Responsive Images plugin with the gallery but I don't think that makes any difference to my problem with the navigation. But just incase this is included just before the above code -

<?php

    //get image alt
    $image_attributes = wp_prepare_attachment_for_js( get_post_thumbnail_id( get_the_ID() ), 'full' );
    $alt = $image_attributes['alt'];
    $url = $image_attributes['url'];
    $id = $image_attributes['id'];

    //pass image url and ID through responsive image plugin
    echo "<img alt='$alt' src='$url' ";
    echo tevkori_get_src_sizes( $id, 'large' );
    echo "/>";

?>

Can anyone help?

zarga on "How to eliminate render blocking CSS? Optimize CSS Delivery"

$
0
0

I have this from google page speed. Anyone have an ideea on how to render blocking CSS?

Eliminate render-blocking JavaScript and CSS in above-the-fold content
Your page has 6 blocking CSS resources. This causes a delay in rendering your page.
None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.
Optimize CSS Delivery of the following:

http://maxcdn.bootstrapcdn.com/…trap/3.2.0/css/bootstrap.min.css?ver=4.1

http://netdna.bootstrapcdn.com/…esome/4.1.0/css/font-awesome.css?ver=4.1

http://fonts.googleapis.com/…ily=Lato%3A300%2C400%2C700%2C900&ver=4.1

juliereader on "Specify USER_ID range for each ROLE in wordpress"

$
0
0

Wordpress automatically assigns USER_ID to the new registered USER. I am actually using 'optional content plugin' to show each ID their respective download link on their "WELCOME PAGE" immediately after they become user on my site. The download link for each user is different.

I am looking forward for a solution to assign different "USER_ID range" to different "Wordpress Role"

For e.g. My membership plugin allows the following roles by default:

S2MemberLevel1 (User ID may range from 1000-19999)
s2MemberLevel2 (User ID may range from 20000-29999)
S2MemberLevel3 (User ID may range from 30000-39999)

The first member of "S2memberlevel1' should automatically be assigned ID#1000 and the second member should be assigned ID#1001 and so on. The same should apply for each role based on their "specified ID-range".

This way it will be easy for me to list download links one by one for each role/level.

Your help would be appreciated.

designrazor on "Duplicate Meta Description Problem"

$
0
0

Hi.,
My blog's navigation menu contains a parent page Web Development and its subcategories html,css3,jquery etc.. And Google webmaster tools is showing duplicate title and meta desciption for some posts as the post is displayed both in parent page and category page.

My permalink structures is
http://www.designrazor.net/%category%/%postname%

I found that I can access the same post with two slugs,
http://www.designrazor/web-development/post-name
http://www.designrazor/css3/post-name

a screenshot of the duplicate content warning is here - image

I dont know how to remove the duplicate content and hope someone will help me.

blog:http://www.designrazor.net

Shaazaam on "Remove email field from registration"

$
0
0

I was wondering how I could remove the email address field from the default registration page.

I am attempting to change the functionality of the registration form slightly. Instead of asking a new user for a username and email, I want them to provide a username and password. From there I have another set of forms for further registration. At this point I will collect a users email. The idea is to streamline registration so a new user will not have to sign up, check their email, then return to the site.

I am developing all of this in a plugin, not a page template, so I will not be adding any code to my theme's functions.php. I have already created a functions file inside my plugin to handle these changes.

DuncanClarke on "post_name and --"

$
0
0

I'm having some trouble on a plugin I'm writing. I need the post_name to match what I tell it, but it keeps replacing consecutive dashes with a single dash. So I use:

'post_name' => 'wegokuhn--jg4ew-g4'

but by the time it gets to the database it's 'wegokuhn-jg4ew-g4'

This is stopping me from effectively identifying duplicate posts. Is there any way to stop this particular action from happening when using wp_insert_post?

Thanks

srohrer on "Hulu video shortcode issue"

$
0
0

I have a page that displays videos from Youtube and Vimeo using shortcodes enabled through Jetpack. It's a custom WP page outside the WP loop.
But I can't get Hulu videos to work. Can anyone help/explain? These are the options I've tried to invoke using do_shortcode($video_string). All of them simply echo the string itself rather than the expected video player. Thanks

[hulu http://www.hulu.com/watch/747521

[hulu=http://www.hulu.com/watch/747521]

[hulu id=747521]

[hulu 747521]

Viewing all 8245 articles
Browse latest View live




Latest Images