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

Fandabydozy on "Add ID selector for each menu item in the WP Menus panel"

$
0
0

Is it possible to add an id tag for each menu item from within the WordPress 'Menus' panel. So it would be possible to go to "Appearance" -->"Menus" --> and then in the screen options panel have an extra checkbox for 'ID' to assign a unique id selector to each main menu item so it can be individually targeted via id=“myUniqueID”.

I’ve included a visual of what I would like to achieve as far as the admin side goes, http://buildtest.co.uk/id-box.jpg.

Thanks


progresst on "wp_update_post ignoring html tags"

$
0
0

I have a custom plugin that moves posts from one category to another and then inserts text after the post is moved. This works fine except for I am trying to insert some CSS like you see below in the $start_text variable.

The wp_update_post function is stripping out the <style type='text/css'> tags completely and treating the contents within the style tags as simple text. How do I make sure those are kept in place when the function runs so the page uses the style I'm trying to import into the post?

Variable:

$start_text="<style type='text/css'>#footerlink { display:none; }</style>Beginning Of posts\n";

The actual Wordpress function:

function toe-knee_cron_hook_action(){
    $my_query22 = new WP_Query;
    	global $start_text;
    	global $catfrom;
    	global $catto;
    	global $dayago;

    					$old_cat = $catfrom;
                        $new_cat = absint($catto);
                        $posts   = $my_query22->query(array('category__in'=>$old_cat, 'post_type'=>'post', 'nopaging'=>'true','date_query' => array('column' => 'post_date_gmt','before'  => $age)));
    					$posts8777=$posts;
    					print_r($posts8777);
                        foreach ($posts as $post) {

                            $current_cats = wp_get_post_categories($post->ID);
                            $current_cats = array_diff($current_cats, $old_cat);
                            if ($new_cat != -1) {
                                $current_cats[] = $new_cat;
                            }

                            if (count($current_cats) == 0) {
                                $current_cats = array(get_option('default_category'));
                            }
                            $current_cats = array_values($current_cats);
                            wp_update_post(array('ID'=>$post->ID,'post_category'=>$current_cats,'post_content'=>$start_text.get_post_field('post_content', $post->ID)));
                        }

     }

DuncanMarshall on "WP generated SQL for orderby meta is super slow on very large DBs"

$
0
0

tl;dr: How do people with hundreds of of thousands of posts deal with very slow queries?

I'm converting a very old and large Phorum installation to BBPress, some queries are extremely slow.

It seems that when a query orders by meta value, this SQL is generated by WordPress:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1  AND wp_posts.post_parent = 9  AND wp_posts.post_type = 'topic' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'closed' OR wp_posts.post_status = 'private' OR wp_posts.post_status = 'hidden') AND (wp_postmeta.meta_key = '_bbp_last_active_time' ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 15

This query takes 20 seconds on my 750k post wp_posts table, with a powerful AWS DB instance. I've already tried DB optimization, and server optimization techniques, and while they have an impact, the query is still taking well over 15 seconds in a best case scenario.

These orderby meta queries are pretty fundamental to BBPress, and I'm not sure it's something I can code out without hacking BBPress core, or WordPress core.

It seems that this is a common problem, and the offered solution is to remove the SQL_CALC_FOUND_ROWS part and achieve pagination in some other way. However, I've tried that, and no dice, it's still slow. I think it's the JOIN that's causing the lag.

I know that this is something that can be dealt with in one way or another, since I see BBPress installations with more posts than mine.

Any solutions?

Thanks.

nigelyork on "Rogue code following a hack"

$
0
0

I have just recovered my site from a hack and have cleared all the files added during that attack, following suggestions found on this site and from my webspace provider.

However, some rogue code remains on the home page. At the bottom of the page, on the far left, below the footer is some code that generates 2 partially hidden links on the page.

I cannot find how to remove these links. I have reviewed a range of php files (funtions.php, footer.php. home.php, etc) but, to be honest, they mean little to me. I am fine with html but not with php so I would not be able to spot wordpress or theme code from anything that's been added.

Any suggestions?

alexrdc on "Automatically Change User Role After x Days"

$
0
0

I'm currently using the User Role Editor plugin along with a function that upgrades a user's role when they purchase a specific product from the site's WooCommerce shop. The function to upgrade the user role is:

add_action( 'woocommerce_order_status_completed', 'upgrade_user_role' );

function upgrade_user_role( $order_id ) {

	$order = new WC_Order( $order_id );
	$items = $order->get_items();

	foreach ( $items as $item ) {
	    $product_name = $item['name'];
	    $product_id = $item['product_id'];
	    $product_variation_id = $item['variation_id'];
	}

	if ( $order->user_id > 0 && $product_id == '3156' ) {
		update_user_meta( $order->user_id, 'paying_customer', 1 );
		$user = new WP_User( $order->user_id );

		// Remove role
		$user->remove_role( 'subscriber' );

		// Add role
		$user->add_role( 'magazine-subscriber' );
	}
}

I would like to modify or add to this function so that after so many days the user role that was added (in this case magazine-subscriber) is removed and the only way to get it back is to buy the product again. I would like to avoid having to install any paid plugins if possible, but would consider it if necessary.

If anyone has any advice on how to achieve this I would really appreciate it!

Jan B-Punkt on "Filter to manipulate the_title AND the_content at the same time"

$
0
0

Hi there community,

I want to create a little plugin to show specific posts only between 10pm and 6am as some kind of youth protection.

I managed to edit the title of the posts with:

function hidefsk16 ($title) {
	$fsk = substr($title,0,7);
	if ($fsk == "[FSK16]") {
		$title = substr($title,8);
		return "FSK16 - ab 22 Uhr freigeschaltet ".$title;
	}
	return $title;
}
add_filter('the_title','hidefsk16');

but I also want to manipulate the content of the post to be something like "No text here. Come back later" instead of the original text.

How can I do that with one filter? Is it possible to do that with only one filter?

Thanks!

PS: Maybe there already is a plugin which does exact this. Show me :)

apaero on "How to have news, albums, interviews (posts) ... related to a band"

$
0
0

Hi, I'm planning on moving my entire music website to Wordpress. And my first though is how could I mantain the basic structure without a headache.

In my site I have the categories 'news', 'album reviews' and 'interviews' related to a specific band, so when I go to mysite/band it shows the last news, reviews and interviews of that band. I would like to have the same structure in Wordpress.

Also, the editor should be able to add specific content to each post depending on the category. Per example, If I add a review, it should contain the rating and the info about the album (label, title, release date, etc.).

I'm almost new with Wordpress but familiar with php (mi entire site is php/mysql) and I would like to know (without too much detail now) how would you implement it in Wordpress, to start in the good way.

Thanks for your time.

Schmee on "Embedded single-quote question"

$
0
0

Hello,

I am trying to employ an add_action (via my child's functions.php) in order to add a meta property to my pages.

Being a very novice PHP user, am running into the simple issue of not knowing how to include the required single quotes around "featured_image" and "url" below.

(for those curious, this simply sets the OG:IMAGE property to a page's featured image.

Any solutions would be appreciated - thank you!

===================

add_action('wp_head', 'my_ogimage');
function my_ogimage() {
echo '<meta property="og:image" content="<?php $featuredImage = get_field('featured_image'); echo esc_url( $featuredImage['url'] ); ?>" />';
}

CostaKapo on "Embed Custom Post Type Into a Page"

$
0
0

I am setting up a site for a friend, it is http://www.realdy.com

It has custom post types that I have set up the user roles to be be such that only a certain level user can post a "property" listing.

Is there a way to embed this custom post type into a page so that these users can make a post from a page rather than click "add new "post""

Thank You

virtous on "Writing a theme in the style of MVC"

$
0
0

Hello Wordpress community!

I'm tackling a task of writing a theme in the MVC style. The theme I'm working on is inspired by Laravel so a lot of the file and folder structures have been borrowed.

So the issue I'm having is that I need Wordpress to edit the .htaccess file from the functions.php file, if that's possible?

Consider the following url,

http://www.website.com/controller/method/params/

I need Wordpress to redirect this url to index.php?url=controller/method/params/
Essentially, everything after "www.website.com/" is the url parameter.

I have managed to solve this by manually editing the .htaccess file so that it looks like this

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ index.php?url=$1 [L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

This seems to work. I can still access files like wp-login.php without the page breaking, and I have access to the url parameter. However, I don't want to manually change this file.

Is there a way for Wordpress to change this for me?

I should add that I've tried to do this with the WP_Rewrite object, but failed. Although I managed to add my custom rewrite rule to the object, it didn't apply to the htaccess.

Help is appreciated.

Johnny Bass on "Register/Login code?"

$
0
0

What code can I use to implement a Register/Login on my site and be secure?

mortrza1371 on "$wpdb->insert or update mysql database if row already exists"

$
0
0

I Write Code with $wpdb Variable to store data in the database..

In The following code , Get Name , Price ,.. From other website with Curl(curl code isn't here now)... every day Curl Get Name , Price ,..

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),

    );
}
}

from example.com and then save in the database table(wp_price)... In The following code every day insert new data value in to the wp_price table and dosen't Save New values replace the previous values ... I want New values replace the previous values .. (namely:today .. liveprice = '2000' , tomorrow liveprice = '2500' ,../

in the follwoing code "$wpdb->insert( $wpdb->prefix" running insert new value of field every run curl example:

title |liveprice|changing|topest|lowest|time

coin | 25$ | 50% | 25$ | 15$ | 20/5/2014 coin | 25$ | 50% | 25$ | 15$ | 21/5/2014 coin | 24$ | 50% | 24$ | 13$ | 22/5/2014

But I don't want add new value of fields .

I want replace new value with previous value.. example

first run insert data ..

title |liveprice|changing|topest|lowest|time

coin | 25$ | 50% | 25$ | 15$ | 20/5/2014

and second run .Replace new values instead previous Values and dont add new row of the new values

title |liveprice|changing|topest|lowest|time

coin | 28$ | 50% | 28$ | 15$ | 21/5/2014

`foreach($table_rows as $tr) { // foreach row

$row = $tr->childNodes;
if($row->item(0)->tagName != 'tblhead') { // avoid headers
$wpdb->insert( $wpdb->prefix . 'fafa',
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'
) );

$wpdb->update( $wpdb->prefix . 'fafa',
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'
) );
}
}`

I Want update data evey day (i.e delete last day data and insert new data )

doktor-x on "Rewrite rule for custom category in a theme, how to change URL addres"

$
0
0

I want to change the url of my wordpress, I have read that I can make that with rewrite rule but it does not work me unfortunately. Here are the details:

I have a wordpress theme, which got me that kind of URL:
www.my-theme.pl/portfolio_category/red-flower/

I want to rewrite the URL via .htaccess to receive:
www.my-theme.pl/gardens/red-flower/

As you see, I just want to replace /portfolio_category/ with /gardens/ text in the URL.

I entered this rule:

RewriteRule ^/portfolio_category/$ /gardens/$ [NC]

And it does not work unfortunately. Can you clarify how to use properly ?
Below is my entire .htaccess code:

`Options -Indexes
AuthType Basic
AuthName "password"
AuthUserFile /home/*******************/.htpasswd
Require valid-user

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/portfolio_category/$ /gardens/$ [NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
# END WordPress`

The ******* are replaced with working path to my htpasswd.
It is my first time to make any rewrite changes and I am not familiar with it. I think I have read the tutorials correctly but the change still does not work.

Best regards from Poland,
Jacek

Shapeshifter 3 on "The WordPress Gallery - Image Link - To An External URL ?"

$
0
0

I'm trying to use The WordPress Gallery (without a Plugin) to create a 3 X 3 Page (not a Post) of 9 images each individually redirected to different external links (browser tabbed). When I go to Gallery Settings, there are only three Link To options available:

1. Attachment Page
2. Media File, or
3. none

The WordPress Visual Editor will not allow me to add links to individual images, and when I tried to use the Text Editor to add an external link to my first image...the whole Gallery disappeared.

Can a 4th option be added the The WordPress Gallery (Link To Settings) that will provide the ability to redirect each image to an external link? I previously had this working using a Columns Plugin, but was trying to see if I could get it to work with The WordPress Gallery instead (The goal is to reduce my number of Plugins, by using Core Components as often as possible).

My current setup is: WordPress 4.2-alpha-31464, the Stargazer Theme, and quite a few plugins .

BeMindful on "Icons wrongly set to Chinese"

$
0
0

Hello, if t here is another thread with this issue please link me to it.

My icons over the entire wptouch app (non pro theme) are showing up as Chinese symbols. I have searched high and low for settings on this, but nothing found. There is nothing on my phone that would indicate it to set in Chinese.

Anyone else have this problem? Is it a bug?

Thank you!

mobile view: http://www.BeMindfulYoureCreative.com


edtiley on "Adding widgets to sidebar programmatically"

$
0
0

I'm trying to add a registered widget to a sidebar programatically.

The idea is to get the current list of active widgets from using get_option('sidebar_widgets') then add an element to the array for the main sidebar, and use update_options() to write the new value to sidebar_widgets. In pseudo-code:
`
$sb = 'sidebar-1'; // the sidebar id to place the widget into
$widget_sets = get_option('sidebars_widgets', array());

// a foreach loop makes sure the sidebar isn't already specified
// if not, use array_unshift to add the widget name
// to the sidebar in the first position
// Since the widget has no settings it shouldn't matter
// what the instance number of the widget is, so append -1
array_unshift($widget_sets[$sb],'my_neaux_widget-1');

update_option('sidebars_widgets', $widget_sets);
'
A print_r() and a manual inspection of the table with PHPmyAdmin both confirm that the sidebar_widgets array now has my_neaux_widget listed, but it doesn't show up in the sidebar.

What is the missing step? If you drag the widget into the sidebar manually, sidebar_widgets is exactly equal to what my code puts there.

Is there a cache that needs to be flushed? Some other option that needs tweaking? The widgets page uses an AJAX call to instantiate the widget. What does that code do differently than update_option()?

Thanks,
Ed

Albert on "Page creation automatization in Wordpress"

$
0
0

Hello to all!

I need to automatize page creation process on Wordpress website.

I have a page with a title, content, permalink and some other attributes (like Social buttons plugin disabled/enabled, page template, comments allowed/disallowed etc.).

Everything is static, but I have to change 1 variable word in title and content for each new page.

Example:

Title: My article about {VARIABLE}
Content: Hello! Today we will talk about {VARIABLE}.

So I need to automatize the process of page creation, for example, if I set variable to "coffee" and then generate such a page, it would be like this:

Title: My article about coffee
Content: Hello! Today we will talk about coffee.

Any ideas how can I do that? Maybe a Wordpress plugin? Or maybe SQL query to duplicate a page (preserving all the attributes) and change {VARIABLE} to a desired word?

Thanks in advance!

LouisIsMyDog on "Function for adding image description and title in the caption."

$
0
0

Hi,

I am stuck on finding/creating a working function to display an images title/description under the image caption. This needs to be something automatic because I have to upload thousands of images. The website I am working on is: Website. The function could just add the image attachment information to the shortcode caption. I tried analyzing the media.php but I am a beginner with php coding. Can someone please help me with this topic?

Thanks,
Emre

aiiiiiight on "Smooth scrolling using jquery/plugins"

$
0
0

Hi all, so I'm having some trouble getting some to work on this website that has a custom theme (I'm trying to get it to work with the black and white menu at the top):

http://etal.info/

At first I just tried to do it using the plugin "Scroll to Page ID" but that hasn't been working either. So I've been trying to program something myself. (Note: I really don't know anything about Jquery and have been mainly copying and pasting from github, developers' websites, etc.).

I think there may be some kind of script conflict, because I've tried to install smooth scrolling using a couple of non-plugin methods, and remnants of that may be laying around. For example, I tried to put this script in header.php, registering it in functions.php:
http://callmenick.com/2013/04/22/single-page-site-with-smooth-scrolling-highlighted-link-and-fixed-navigation/

I went into a whole rigamarole with jQuery, registering and enqueueing some non-plugin scripts because the site doesn't appear to be loading anything jQuery or Javascript-related at all. Something, I believe, should be appearing in the console when I click on my header links, but there isn't even a sign of failure. It seems things should be much simpler than this. Help?

PS: I've taken the steps in this thread to no avail:
Here.

Kees-V on "Tags under post and above plugins"

$
0
0

I first had the tags under the post.
But since I use a customer reviews and a related posts plugin they are shown first.

It is possible to change this. So first the tags and then te Customer Review and the related posts.

See for an example: http://www.despreker.nl/guido-thys/

Thanks.

Viewing all 8245 articles
Browse latest View live