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

aus007 on "Woo commerce External Affiliate store without product pages"

0
0

Any ideas, what settings/plugins or code hacks to change in wordpress/woocommerce, if I do not want product pages. Like when ever someone clicks on product link/Image they are taken direct to Amazon or other affiliate website from category/product listings page itself ?


Deexgnome on "Save custom Excerp to Meta"

0
0

Hey,

i trying to create a own custom excerp and save the value to the Meta of the post. My Goal overall is to save the first h2 to the meta and attach a dot to it.

For the beginning i'm trying to save the auto excerp of wordpress to the meta without any filtering. But for some reason this field stays empty if i save the post. I hope that someone could tell me whats wrong with the script (functions.php).

add_action( 'save_post', 'h2_excerpt_save' );
function h2_excerpt_save( $post_id )
{
    if ( $_POST['post_type'] == 'post' ) {
        add_post_meta($post_id, 'h2_excerpt_field', get_the_excerpt($post_id), true);
    }
}

nogenius on "Price modification in mini cart"

0
0

Hi everyone,

I am currently writing a plugin displaying custom fields for a product which have an impact on the price.
I have managed to update the prices in the cart and the order page by overwriting the coresponding price in the cart object within add_action( 'woocommerce_before_calculate_totals', ....

This works fine besides the fact, that in the mini-cart widget the sum of all items is shown correct, but the price of a single item does not reflect these changes.
E.g. the original product costs 10 EUR, the value is overwritten with 20 EUR. The result in the mini cart would be a display of

Product A
1 × 10 EUR

Subtotal: 20 EUR

So in subtotal the price is considered, in the pure price of one product not.

What I don't get is that if I am not completely wrong, both values are in the end calculated by using the product->get_price() functions...

Is there any way to get both values updated or any kind of workaround?
Thanks in advance!

lobaath on "If "this" category has children, show them other wise show parent"

0
0

Hi Could anybody help me solve this little dilemma.

I want to list post category, but if the post is in category 3, then list the children of that cat. Check my code out below.

<?
$categories = get_the_category();
$creative_field = array();
$location = array();
$auktion = array();

foreach ($categories as $cat) {
  if ($cat->parent == 3) { //Formgivare
    $creative_field[] = '<a>cat_ID).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>';
  } else if($cat->parent == 1){ //Samlare
    $location[] = '<a>cat_ID).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>';
  }	else if ($cat->parent == 16){ //Auktion och alla andra
    $auktion[] = '<a>cat_ID).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>';
  }
}

if(!empty($creative_field)){
  print "". implode(", ",$creative_field);
}

if(!empty($location)){
  print "". implode(", ",$location);
}

if(!empty($auktion)){
  print "". implode(", ",$auktion);
}

?>

David Gewirtz on "How to hide custom post types from Google?"

0
0

I have a plugin that implements custom post types. Recently, some of my users have noticed that the individual pages for a custom type is being indexed by Google (and presumably other search engines). This is even though there's no front-end index of any pages that use that post type.

I know there's an exclude_from_search option when registering the type, but that appears to be for WordPress search. Is there a way (or best practice) to make sure that the individual posts created for a custom post type are simply not visible to the outside world at all?

Thanks!

--David

Guido on "Get post meta (date) outside loop"

0
0

Hi,

I have a variable called 'today' and I'm using this to list events on date. I have added a custom meta field called 'event-days' to add extra days to variable 'today'.

But it doesn't work.
Note: it's located outside the loop and that's why I call the wp_query for the 'event_days'.

global $wp_query;
$postid = $wp_query->post->ID;
$event_days = get_post_meta( $postid, 'event-days', true );

$now = strtotime('today');
if ($event_days == 'two') {
	$today = strtotime($now . "+1 day");
} else if ($event_days == 'three') {
	$today = strtotime($now . "+2 days");
} else if ($event_days == 'four') {
	$today = strtotime($now . "+3 days");
} else {
	$today = strtotime('today');
}

Suggestions? I think it might has something to do with being outside the loop.

Guido

Wayn on "Custom Post Type Archive by Date"

0
0

Hi all

I need to apply this rewrite rule to multiple custom post types.

Currently it is only using one cpt "articles" but i need it to apply to "articles" & "newsletters"

How do i change the code to both these custom post types

/**
 * Custom post type specific rewrite rules
 * @return wp_rewrite Rewrite rules handled by WordPress
 */
function cpt_rewrite_rules($wp_rewrite)
{
    // Here we're hardcoding the CPT in, article in this case
    $rules = cpt_generate_date_archives('article', $wp_rewrite);
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
    return $wp_rewrite;
}
add_action('generate_rewrite_rules', 'cpt_rewrite_rules');

/**
 * Generate date archive rewrite rules for a given custom post type
 * @param  string $cpt slug of the custom post type
 * @return rules       returns a set of rewrite rules for WordPress to handle
 */
function cpt_generate_date_archives($cpt, $wp_rewrite)
{
    $rules = array();

    $post_type = get_post_type_object($cpt);
    $slug_archive = $post_type->has_archive;
    if ($slug_archive === false) {
        return $rules;
    }
    if ($slug_archive === true) {
        // Here's my edit to the original function, let's pick up
        // custom slug from the post type object if user has
        // specified one.
        $slug_archive = $post_type->rewrite['slug'];
    }

    $dates = array(
        array(
            'rule' => "([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})",
            'vars' => array('year', 'monthnum', 'day')
        ),
        array(
            'rule' => "([0-9]{4})/([0-9]{1,2})",
            'vars' => array('year', 'monthnum')
        ),
        array(
            'rule' => "([0-9]{4})",
            'vars' => array('year')
        )
    );

    foreach ($dates as $data) {
        $query = 'index.php?post_type='.$cpt;
        $rule = $slug_archive.'/'.$data['rule'];

        $i = 1;
        foreach ($data['vars'] as $var) {
            $query.= '&'.$var.'='.$wp_rewrite->preg_index($i);
            $i++;
        }

        $rules[$rule."/?$"] = $query;
        $rules[$rule."/feed/(feed|rdf|rss|rss2|atom)/?$"] = $query."&feed=".$wp_rewrite->preg_index($i);
        $rules[$rule."/(feed|rdf|rss|rss2|atom)/?$"] = $query."&feed=".$wp_rewrite->preg_index($i);
        $rules[$rule."/page/([0-9]{1,})/?$"] = $query."&paged=".$wp_rewrite->preg_index($i);
    }
    return $rules;
}

exaju on "Remove articles from search result"

0
0

Hi everyone,

I have to exclude some articles based on a name of a person from the search results.

I found the file ttps://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/query.php and I think I have to modify it in order to exclude posts from results.

I do not took the time to read the entire file (Im' a little bit lazy and also I have to find a solution in the next two days...) because perhaps someone has the name of a method to override to point to my vue (it will be great).

Let me know if you need some more informations in order to answer my question and sorry if it seems that I did not search enough, I can do some more work by myself if needed.

Any help would be very appreciated !

Best Regards.


chrstna on "PHP shortcode of custom plugin returning white screen"

0
0

Hi,

So there is a custom plugin that was being used on http://www.brownlowtracker.com.au that displays a horizontal scroll of AFL scores above the header.

I changed the theme it was using, and now the plugin doesn't work.

I am using code <?php do_shortcode('[matchesscore]'); ?> (this was in the original theme file of header.php that worked) in the new theme's header.php file, but it just returns a white screen.

I'm not sure where the issue is. Is it is the new theme's header?

Let me know what code/files you need to see.

Thanks for your help.

Regards,

Christina

bungeebones on "Themes crash after iframe loaded"

0
0

I may have to scrap this whole approach so if someone has a better way to accomplish this then, please, let me know ... but otherwise, this approach works except for iframes stopping the theme loading process.

How this works:
I have the main plugin page (example.php) that loads via a shorttag on a typical Wordpress page (let's say mysite.com/advertise (note permalinks are set to Post Name).

So the visitor goes to http://www.mysite.com/advertise and the plugin does it's thing and loads a page. Along the top of that page are some links to other pages that I placed in a folder named "endorsements" inside the plugin folder. So let's say the visitor clicks the link "Add Url". It displays in the browser like this - http://www.mysite.com/advertise/?add_url=true&affiliate_num=7659

The server will treat that request in a manner like it was PHPSELF and loads the plugin's original main page. Then through a series of conditional "if" statements it includes another PHP page using the include function like this:

if(ISSET($_GET['add_url'])){
include('endorsements/add_url.php');
}

The page "included" is just straight html but has an iframe that loads a form from a remote server. One theme completely crashes and only displays a spinner. The other themes all load up to and including the iframe but everything after the iframe is missing (no right sidebars, no footers).

What would be the best way out of this?

I see the following options:
1) Have the user install and configure an iframe plugin to handle the iframe properly and keep it from breaking the page load
2) Have my plugin detect the error and display just a link to the remote page rather than an iframe.

stabilimenta on "if testing value of array value inside a foreach loop"

0
0

I am creating a shortcode that returns various meta data depending on the shortcode attributes.
The shortcode I have on my page looks something like this:
[contactinfo include="name, title"]
The function that creates the shortcode looks like this:

function contactinfo_shortcode( $atts ) {
	extract( shortcode_atts(
		array(
			'include' => 'all',
		), $atts )
	);

	$output = "";
	$value = array($include);
	$value = explode(',', $include);
	foreach ($value as $att_id) {
		if ($att_id == 'name') {
			if (get_option('stab_contact_name')) {
				$output .= "<div class=\"name\">" . get_option('stab_contact_name') . "</div>\n";
			}
		}
		elseif ($att_id == 'title') {
			if (get_option('stab_contact_job_title')) {
				$output .= "<div class=\"job-title\">" . get_option('stab_contact_job_title') . "</div>\n";
			}
		}
	} // foreach

	return $output;
}
add_shortcode( 'contactinfo', 'contactinfo_shortcode' );

The problem that has me stumped is that the loop never makes it past the "name".
I tried it using a switch/case method, but that wasn't allowing me to control the order of the data items being returned, for example if the shortcode was set [contactinfo include="title, name"] instead of [contactinfo include="name, title"].

Can anyone advise me? Thanks!

Bawse1010 on "Image Hover CSS"

0
0

I am using the Divi theme..
The site is http://www.aveladesign.com

I am trying to get a caption to hover over the images on the homepage. I have css on the images to turn them from grayscale to color on hover, but I want to add a caption on hover to the bottom of the circles. Right now they only have the tags and that isnt what I want

For example, when the mouse hovers over the first circle, it should turn to color and "Logos" should also appear with a transparent black background within the circle. Right now, "logos" only appears in the small tag on hover.

I know the css to ONLY do the caption on hover, but not both the grayscale to color affect and the caption on hover. Any ideas?

wordstress2016 on ".htaccessProblem"

0
0

I have lots of bad back links and bad keyword content showing up.I was wondering if this could have anything to do with my .htaccess file. the code is below. I have seen it before and it just does not look like it should.
-------------------------------------------------------------------------------------------
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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

# BEGIN wtwp_cache
<IfModule mod_mime.c>

# Text
AddType text/css .css
AddType application/x-javascript .js
AddType text/html .html .htm
AddType text/richtext .rtf .rtx
AddType text/plain .txt
AddType text/xml .xml

# Image
AddType image/gif .gif
AddType image/x-icon .ico
AddType image/jpeg .jpg .jpeg .jpe
AddType image/png .png
AddType image/svg+xml .svg .svgz

# Video
AddType video/asf .asf .asx .wax .wmv .wmx
AddType video/avi .avi
AddType video/quicktime .mov .qt
AddType video/mp4 .mp4 .m4v
AddType video/mpeg .mpeg .mpg .mpe

# PDF
AddType application/pdf .pdf

# Flash
AddType application/x-shockwave-flash .swf

# Font
AddType application/x-font-ttf .ttf .ttc
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-otf .otf

# Audio
AddType audio/mpeg .mp3 .m4a
AddType audio/ogg .ogg
AddType audio/wav .wav
AddType audio/wma .wma

# Zip/Tar
AddType application/x-tar .tar
AddType application/x-gzip .gz .gzip
AddType application/zip .zip
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On

# Text
ExpiresByType text/css A31536000
ExpiresByType application/x-javascript A31536000
ExpiresByType text/html A3600
ExpiresByType text/richtext A3600
ExpiresByType text/plain A3600
ExpiresByType text/xml A3600

# Image
ExpiresByType image/gif A31536000
ExpiresByType image/x-icon A31536000
ExpiresByType image/jpeg A31536000
ExpiresByType image/png A31536000
ExpiresByType image/svg+xml A31536000

# Video
ExpiresByType video/asf A31536000
ExpiresByType video/avi A31536000
ExpiresByType video/quicktime A31536000
ExpiresByType video/mp4 A31536000
ExpiresByType video/mpeg A31536000

# PDF
ExpiresByType application/pdf A31536000

# Flash
ExpiresByType application/x-shockwave-flash A31536000

# Font
ExpiresByType application/x-font-ttf A31536000
ExpiresByType application/vnd.ms-fontobject A31536000
ExpiresByType application/x-font-otf A31536000

# Audio
ExpiresByType audio/mpeg A31536000
ExpiresByType audio/ogg A31536000
ExpiresByType audio/wav A31536000
ExpiresByType audio/wma A31536000

# Zip/Tar
ExpiresByType application/x-tar A31536000
ExpiresByType application/x-gzip A31536000
ExpiresByType application/zip A31536000
</IfModule>
<FilesMatch "\.(?i:css|js|htm|html|rtf|rtx|txt|xml|gif|ico|jpg|jpeg|jpe|png|svg|svgz|asf|asx|wax|wmv|wmx|avi|mov|qt|mp4|m4v|mpeg|mpg|mpe|pdf|swf|ttf|ttc|eot|otf|mp3|m4a|ogg|wav|wma|tar|gz|gzip|zip)$">
<IfModule mod_headers.c>
Header set Pragma "public"
Header append Cache-Control "public, must-revalidate, proxy-revalidate"
Header unset ETag
</IfModule>
</FilesMatch>
<FilesMatch "\.(?i:css|js|gif|ico|jpg|jpeg|jpe|png|pdf|swf|ttf|ttc|eot|otf)$">
<IfModule mod_headers.c>
Header unset Set-Cookie
</IfModule>
</FilesMatch>
# END wtwp_cache
# BEGIN wtwp_security
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>
<Files "wp-config.php">
Order allow,deny
Deny from all
</Files>
Options -Indexes
# END wtwp_security
-----------------------------------------------------------------------------------------

Any help would be appreciated these spam backlinks are killing my SEO work.

Thank you

iamnotjerry on "Need to change WP Dashboard Access Password"

0
0

I stand a good chance of my site being hacked. A so called web designer has login and password and I need to change it asap. I went to the users page changed my profile as Admin, but it did not change access to dashboard.
Thank You...

enriquerene on "enqueue scripts JS"

0
0

I used in my option page, to style it:

function easydm_add_link_tag_to_head() {
	wp_enqueue_style( 'easydm-style', '/'.EASYDM_CSS_PATH.'style.css', array(), null, 'all' );
	wp_enqueue_style( 'easydm-manager', '/'.EASYDM_CSS_PATH.'manager.css', array(), null, 'all' );
}
- - - - - -
add_action( 'admin_enqueue_scripts', 'easydm_add_link_tag_to_head' );

Now I'm trying to do the same but with JS files but this doesn't work:

function easydm_add_script_tag_to_head() {
	wp_enqueue_script( 'easydm-file-ui', '/'.EASYDM_JS_PATH.'file-manager.js' );
}
- - - - - - -
add_action( 'admin_enqueue_scripts', 'easydm_add_script_tag_to_head' );

What is my mistake? Some other way to follow?


MaWe4585 on "how to handle timestamps"

0
0

hello,

in my plugin i use custom-tables and want to store timestamps of events in the future. the server is in the timezone Europe/Berlin but i want to store the timestaps without timezone to render them later into the timezone of the user.

is there a best practice for working with timestamps and timezones?
what type should i use for the mysql-table?
how do i get a user-posted timestamp to a timestamp without timezone and the other way around?

MaWe4585 on "select all posts where meta-key doesn't exist or has certain value"

0
0

Hello,

i create some posts and added a meta-value with the key "example".

now i want to select all posts where this meta-key is empty or have the value "test"

how can i do that?

here i can either use a meta-key or not but not both...

$args = array(
        'posts_per_page' => 5,
        'offset' => 0,
        'category' => '',
        'category_name' => '',
        'orderby' => 'title',
        'order' => 'ASC',
        'include' => '',
        'exclude' => '',
        'meta_key' => '',
        'meta_value' => '',
        'post_type' => 'mytype',
        'post_mime_type' => '',
        'post_parent' => '',
        'author' => '',
        'post_status' => 'publish',
        'suppress_filters' => true
    );
    get_posts($args);

felzend on "Related to add_menu_page"

0
0

Hello.

How do I do to redirect to an page I created on my plugin folder? Instead of rendering a template inside "function".

add_menu_page('Adicionar produto', 'Adicionar Produto', 'manage_options', 'index_func', 'index_func');

Also only am able to redirect to a page which is inside wp-admin folder? Would like to redirect, for example, to "wp-content/MY_PLUGIN_NAME/MY_PAGE.PHP"

Is this possible?

Thanks.

jaytor05 on "Calling specific category to front page"

0
0

I am trying to call a specific category post to my front page including the feature image (which becomes the background image in the section) and title. Below are the snippets but for some reason nothing is showing up. Any tips would be appreciated.

Here is the link to my website

http://www.johannesterry.ca/joie/

<!-- FEATURE BLOGS -->
	<?php
		$feature_posts = array_reverse(get_posts(array(
                        'posts_per_page'   => 3,
                        'offset'           => 0,
                        'category_name'    => 'feature-posts')));
    ?>

    <?php foreach($feature_posts as $feature_post): ?>
	<?php $post_custom_fields = get_post_meta($feature_post->ID); ?>

    <div id="info-box-sect" class="info-box-sect">
		<div class="expanded row">

		  	<!-- BOXES REPEAT -->

		  	<div class="medium-4 columns box"
		  		style="background: linear-gradient( rgba(109, 30, 42, 0.4), rgba(109, 30, 42, 0.4) ), url('<?php echo $image[0]; ?>'); background-size: cover;">

		    	<span class="joie-category"><?php echo $post_custom_fields['main_category'][0];?></span>

			    <div class="medium-9 outside-box">
			      <div class="inside-box blg-title">

			        <h4><?php echo $feature_posts->post_title; ?></h4>

			      </div>
			    </div>

		  	</div><!-- BOXES END -->
			<?php endforeach; ?>

		</div>
    </div>

devonmather on "Adding a wp_editor to a modal, edit gallery button not displaying?"

0
0

I've initialized a wp_editor via ajax with quick tags within a wp-media modal, and everything seems to be working great. However If I try and edit a gallery within the modal by clicking it nothing happens... Has anyone experienced this issue?

I can add a gallery, oembeds etc. to it fine.

If I load the same code outside of the modal, the 'hover edit' menu works fine. So it seems to be related to the fact that the editor is alerady opened in a modal.

Example image of the missing tooltip.

Viewing all 8245 articles
Browse latest View live




Latest Images