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

T3chnique_Chr1s on "Post catagories onto a page"

$
0
0

Hi All,

I'm currently using PHP to call posts of a certain category onto a page. The posts have to be limited to 26, however I want to hide the 'Older Entries' button at the end of the list.
The link has no CSS style linked to it, so I can't use CSS to hide it. Is there anything I can add into the PHP to not display the older entries link?

<?php
$current_year = date('Y');
$args = array(
	'category_name' => 'happenings',
	'year'     => date("Y"),
	'order'    => 'DESC',
	'showposts' => 26

);

query_posts( $args );

while (have_posts()) : the_post();
  // do whatever you want
?>

Thanks!

Chris


Yasp0 on "Front end form, how to add extra taxonomies?"

$
0
0

I am using the code below with a front end form. People can fill in the form and use 3 select fields to select soms values. I managed to get it working, but only for 1 of the 3 select fields.

How do I add the 2 extra taxonomies to this code?

<?php

$postTitleError = '';

if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {

	if(trim($_POST['postTitle']) === '') {
		$postTitleError = 'Please enter a title.';
		$hasError = true;
	} else {
		$postTitle = trim($_POST['postTitle']);
	}

	$post_cat = $_POST['cat'];

	$post_information = array(
		'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
		'post_content' => esc_attr(strip_tags($_POST['postContent'])),
		'post_type' => 'reports',
		'post_category' =>   $post_cat,
		'post_status' => 'pending'
	);

	$post_id = wp_insert_post($post_information);

	wp_set_post_terms( $post_id, $_POST['cat'], 'report_category', false );

	if($post_id)
	{
		wp_redirect(home_url('/thanks'));
		exit;
	}

}

?>

Jamel.Z on "Get current plugin from loaded admin page"

$
0
0

Hi

in the admin side I wanted to create a function which returns the name of the current plugin

something like this:

$current_plugin_name=get_current_plugin();

MikePirch on "Product category page does not display subcategories products"

$
0
0

I set up a page using shortcode [product_categories number="X" parent="X"] and it shows the pictures of the subcategories. The problem is that for some reason only one subcategory opens correctly (with the "Sort by" etc.) but all other subcategories show "No products found which match your selection" error.

Does anybody know the solution for this?

Any help is appreciated.

Jith3003 on "How to restrict access to .htaccess file i.e. web-config"

$
0
0

How to restrict access to .htaccess file i.e. web-config in case of WordPress hosted on windows server.

Please provide step by step process to do it.

tomybyte on "How to log the actual value of a variable or constant in a plugin or the wp core"

$
0
0

I just want to know the standard wordpress way to write the actual value of a variable or constant in a PHP file of a plugin or the wp core at any code line to a log file. It would be cool if the output could look like:
timespamp | filename | line-number | name (of variable or constant) | the actual value of the variable or constant
if the variable is an array it would be nice if it would be possible to list the key/value or name/value pairs as sublist like:
timespamp | filename | line-number | name (of the array variable) | is an array
key/value
key/value
key/value
...
or objects:
timespamp | filename | line-number | name (of the object) | is an object

or like that

May be there is a plugin for that available. I don't want to reinvent the wheel!

Thank you for support!

Tom

danina84 on "Placing in head vs functions.php"

$
0
0

Hi,
I was wondering if it better(for performance) to put noindex, follow and meta descriptions in a child theme's head.php or the child theme's functions.php. I know when placed in the functions I will not have problems in case of theme updates, but what is better for performance?
Thanks.

kustv on "Redirect to homepage"

$
0
0

Hi,
I have deactivated some archives though this

add_action('template_redirect', 'remove_wp_archives');
function remove_wp_archives(){

  if( is_category() || is_tag() || is_date() || is_author() ) {
    global $wp_query;
    $wp_query->set_404();
  }
}

but I would like to redirect to my homepage instead of 404. How can I achieve this?


rdcalex on "Multiple User Role Upgrades on Purchase with WooCommerce"

$
0
0

I've been able to successfully implement a function that upgrades a user's role when a specific product is purchased. The problem I'm having now is that I have multiple products that each assign unique roles and when more than one of these products is purchased together only the first product's user role is added. I need to find a way to add all of the necessary roles at once if someone purchases multiple products at the same time.

Here's the current code I'm using:

// Fall 2014

add_action( 'woocommerce_order_status_completed', 'upgrade_fall_2014' );

function upgrade_fall_2014( $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 == '3326' ) {
		update_user_meta( $order->user_id );

		update_user_meta( $order->user_id, 'fall_2014_expiration', time() + (30 * 24 * 60 * 60) );

		$user = new WP_User( $order->user_id );

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

// Summer 2014

add_action( 'woocommerce_order_status_completed', 'upgrade_summer_2014' );

function upgrade_summer_2014( $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 == '3800' ) {
		update_user_meta( $order->user_id );

		update_user_meta( $order->user_id, 'summer_2014_expiration', time() + (30 * 24 * 60 * 60) );

		$user = new WP_User( $order->user_id );

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

muydelpalo on "Full background gallery image"

$
0
0

Hi! I've been googling for some time and almost everything I find are plugins that display a single gallery of photos sliding on the background of posts, pages...

What I am trying to achieve is a bit different. I am setting up a portfolio page. Each post is a project that has some photographs (different for each project). I have uploaded them to the post and created a gallery. This is what I am trying to achieve:

When you visit the post, the full background is one of the images of the project. There is an arrow in the left and another one in the right, to navigate to the previous/next image. So all you see are the pictures. Then, if you scroll down, a small piece of text comes up so you can read a description about the project. If you scroll down again the text goes.

I think it is simple, but can't seem to find the right way to look for a solution. Any ideas? Thanks!

HugoN on "Adding meta titles for paginated pages"

$
0
0

Hello,
I have added this to my head
if ( $paged >= 2 || $page >= 2 ) echo ' | ' . sprintf( __( 'Page %s'), max( $paged, $page ) );
in order for the meta title of paginated pages to also show the page number, but I would like the page number to be displayed BEFORE the site's name, like this
Uncategoried | Page 2 | mysite
How would it need to be changed?

yick08 on "Creating A New Feature Like "Posts""

$
0
0

I'm doing a contract I need to create a feature on an existing WP site that functions almost exactly like Posts, but has custom fields (note, I can't use Posts as the client is already using it for their Blog).

Basically, I want to have a menu option on the side of the wp-admin called "Features". When you click that, it opens up a summary of all the "features" that already exist (exactly like "Posts"). You can create a feature, or edit an existing one. The fields to fill are a title, date (maybe), name, body, preview, image link, and external link; nothing more, nothing less. Then I will have a template that renders out that content in a defined way, and another page that lists all of the features showing just the title, preview and image in reverse-chronological order (newest on top).

Is this something that I can do with just a normal installation of WordPress? Is there a plugin that exists that will do this for me? Do I need to develop my own plugin?

Any help would be appreciated, thanks.

nielsborn on "Scroll to anchor on specific page"

$
0
0

I'm building a Wordpress website and I'm trying to scroll to an anchor on specific pages. My idea is to detect on which page the visitor is based on de URL. If the URL is http://website.com/targetterm/category/test I would like the script to detect the term targetterm and automatically scroll to an anchor on these pages.

Is there anyone who has an idea how to achieve this?

Thanks!

tampadave on "Source Code Mapping"

$
0
0

Hello to all, this is my first posting on WP, and I've looked for this all over the place, but I still haven't found what I'm looking for. :-)

I am new to wordpress, but not developing. I took a five year break from it, between 2008 and 2013, due to job restrictions, but I'm back, and ready to go.

I code on Ubuntu 12.04lts, localhost >> LAMP. emacs is my favorite editor, but I am entirely flexible. OOP presents its own needs.

My current problem is that I need to develop a plugin that adds SKU regex'd pricing policy within woocommerce and the compatible theme responsive, from cyberchimps(sp?).

My trouble with this problem is that reading code does nothing but put me into a maze of twisty little includes, all alike.

Just to see, I tallied up an estimate of how many pages of code were involved with the post "hello world." and it was about 1500. Ouch!

How do I emphatically determine which hooks to use to include my own functions, and what the variable names are on which to operate?

I am not even sure of the source file that renders any given page.

Are there any debuggers, gnu's ddd for php5/wordpress? I sense a conspiracy against the ability to read and follow code....

Thanks in advance!

Also, any feedback on bluefish and/or eclipse and/or phpdbg?

David, Tampa, Florida.

jaiunblog on "Large image in image_constrain_size_for_editor in wp_prepare_attachment_for_js"

$
0
0

Hi,

My large image is 1440px on width and 9999px on height.
When I used wp_prepare_attachment_for_js, I get a wrong size for large image, I found where and why but don't understand this :

elseif ( $size == 'large' ) {
		/*
		 * We're inserting a large size image into the editor. If it's a really
		 * big image we'll scale it down to fit reasonably within the editor
		 * itself, and within the theme's content width if it's known. The user
		 * can resize it in the editor if they wish.
		 */
		$max_width = intval(get_option('large_size_w'));
		$max_height = intval(get_option('large_size_h'));
		if ( intval($content_width) > 0 )
			$max_width = min( intval($content_width), $max_width );
	} elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
		$max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
		$max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
		if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing.
			$max_width = min( intval($content_width), $max_width );
	}

from media.php
How to hack this, I would like to get (best way with less request) width, height and url from a wordpress gallery.


ijyoung on "get categories"

$
0
0

I am developing a course booking system.
There are four dropdown boxes per page
Each course is available on certain dates and I have used categories as a means of identifying those dates.
On selecting the course some javascript opens up a dropdown list of available weeks.This all works fine

On the edit page we use a version of the dropdown list so prospects can change the date.
If only one course booked everything works well but on the second and subsequent course bookings - the drop down list of dates has multiple entries.

everything is driven by session variable at this stage

'<input type="hidden" name= "course1a" value="<?php echo $crs1a;?>,<?php echo the_field('cost_of_course',$id1); ?>" />
<select name="date1a" id="date1a">
<?php if($id1==''){?>
<option value="">Select Week</option>
<?php } else{ ?>
<option selected="selected" value="<?=$date1a?>"><?=$date1a?></option>
<?php } ?>

<?php
$categories =get_the_category($id1);
foreach ($categories as $category) {

if($category->name !== '6 +')
if($category->name !== '7+')
if($category->name !== '8+')
if($category->name !== '9+')
if($category->name !== '10 +')
if($category->name !== '11+')
if($category->name !== 'All')

$option = '<option value="'.$category->cat_name.'">';
$option .= $category->cat_name;
$option .= '</option>';
echo $option;
}
?>'
Each course has a version of this (it was the simplest way I could think of to effect it).
Any thoughts as to what is going on?

kasperfranz on "Best way to achieve a module with a set of dates."

$
0
0

Hey everyone.

I have a customer there wants a post Type which is a "module" (which basicly is a set of dates with information about place and so on)

I was thinking that this might be able to be done using Custom meta fields, but the only problem I can see with this is that I can't let i have for example 10 in one and then 5 in another.

And i need it to be shown on a page (and being able to search through them also).

I hope you have some points to what i can do and how it can be done (existing source would also be nice but not needed).

kitchin on "Should Akismet and Jetpack "OPTIMIZE TABLE" core tables?"

$
0
0

Both Akismet and Jetpack Contact Form (Grunion) have this code, run from a cron:

if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->comments ) ) // lucky number
	$wpdb->query("OPTIMIZE TABLE {$wpdb->comments}");

In Jetpack Contact Form it's the same, except with 'grunion_optimize_table' and $wpdb->posts.

In core WP, 'OPTIMIZE TABLE' only appears once, protected by WP_ALLOW_REPAIR and various scare techniques like warning "Repairing and optimizing the database can take a long time and the database will be locked while optimizing" and telling the user to delete the constant when done.

Here's my issue:

* Since it runs 1 out of 5000 times, any problems this code causes will be extremely intermittent and difficult to diagnose.

* InnoDB tables recreate + analyze rather than optimize. Is that bad?

* May encourage plugin authors to do similar stuff, since Akismet and Jetpack are semi-official.

This stuff has been in the code since the beginning of time, and there is no discussion on core trac, plugin trac, these forums, wp stack exchange, or in Google. So I'm starting one!

vpsilva on "Error in place of Price - woocommerce"

$
0
0

In my account-page when show price, show this message:

Warning: sprintf(): Too few arguments in /home/cf/public_html/wp-content/plugins/woocommerce-subscriptions/classes/class-wc-subscriptions-manager.php on line 2815

In the description of the products, the price is displayed R $ 598.80 - Brazilian currency .

When I go into my account and price .. displays the error.

Theme Flatsome 2.6.1

buznuts on "redirection help"

$
0
0

hello, i have entered a piece of code to my child header file that redirects a user to my news-feed page if they were still logged in, and now i have added another piece of code to it, which redirects to home page if they are not logged in, it seems to work but i have a feeling i’m going about this the wrong way! shouldn’t i use a case statement or if else instead, i done a bit of basic programming in pascal 20 years ago, and don’t have a clue any more! here is what i have:

if (is_user_logged_in() && is_front_page() ) {
wp_redirect(‘http://www.website.com/news-feed’);
exit;
}
if (!is_user_logged_in() && !is_front_page()) {
wp_redirect(‘http://www.website.com’);
exit;
}

is there a better way of writing this?

also although this works for most pages, if i go to http://www.website.com/admin or wp-admin i get the wordpress login box, i would prefer it if that also redirected to home page so admin also have to login from there. is this possible?

many thanks

Reply

Viewing all 8245 articles
Browse latest View live




Latest Images