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

toneburst on "Sort Posts By Multiple Meta Values"

$
0
0

Hi,

I have written a plugin to create a custom post-type. I want to set the default sort-order for posts of this custom type when they display on their own archive page.

I've managed to get them to sort by one custom meta key value, but I need them to also be sorted by the value of a second meta key.

I want posts to be sorted by year of graduation (it's a university alumni site), then by first name.

I can't seem to get it to work, though I've found lots of posts where others are failing to do the same thing.

Here's the code I have so far:

public function majal_pre_get_posts_alumni_sortorder( $query ) {
	if ( !is_admin() && $query->is_main_query() && $query->is_post_type_archive( 'majal_alumni' ) && !isset( $_GET['orderby'] ) ) {
		$query->set( 'meta_key', '_majal_alumni_alumnus_graduationyear' );
		$query->set( 'orderby', 'meta_value' );
		$query->set( 'order', 'DESC' );
		$query->set( 'meta_query', array(
			array(
				'key'		=> '_majal_alumni_alumnus_namesecond',
				'orderby'	=> 'meta_value',
				'order'		=> 'ASC'
			)
		));
		$query->set( 'posts_per_page', '16' );
		$query->set( 'paged', true );
	}
}

This function is called by the 'pre_get_posts' filter hook. I know it's getting called correctly, as my posts are being correctly sorted on '_majal_alumni_alumnus_graduationyear', but they're not then being sorted by '_majal_alumni_alumnus_namesecond'.

I want posts with identical values for graduationyear to be grouped together, but then sorted by namesecond.

Anyone any ideas?


toneburst on "Default Post Sorting For Custom Post-Type"

$
0
0

Hi,

I have made a plugin that creates a custom post-type, and I want to make sure that posts on the post-type archive page for this type are sorted in a particular order.

I have the below in the PHP plugin class that defines the custom post-type:

public function majal_pre_get_posts_alumni_sortorder( $query ) {
	if ( !is_admin() && $query->is_main_query() ) {

		if ( $query->is_post_type_archive( 'Alumni' ) ) {
			if( !isset( $_GET['orderby'] ) ) {
				$query->set( 'orderby', 'title' );
				$query->set( 'order', 'ASC' );
			}
		}
	}
}

This function is hooked from the pre_get_posts filter.

This doesn't seem to work- posts are still ordered by ID (or date, not sure) on the archive page for the post-type.

Anyone any clues as to what I'm doing wrong?

Cheers,

Alex

morollian on "Page with the same name as an actual directory"

$
0
0

Hello!
I'm having troubles with a website based on Wordpress 4.0.

In my website there is a page wich must have certain name, let's call it mandatory_name. I can do nothing about it because this name (and consequently the url) are mandatory by law. The problem is that already exisits a directory with the same name.

THE PROBLEM: When a user types the url http://www.mywebsite/mandatory_name, the browser shows the content of the folder /mandatory_name instead of the content of the page "mandatory_name".

Any clue would be very appreciated... I'm so lost here!

Frank Gomez on "Add Script ONLY to head of single posts"

$
0
0

I'm trying to add a script only to the head of single posts (not pages, not images, nothing else, just regular single posts.

I've tried several things and this is my last attempt

/*  ADD KISSMTRICS SCRIPT TO ONLY POSTS */
 if (is_singular( 'post' )) { ?>
<script>
_kmq.push(['trackSubmit', '.single-post-optin', 'Filled Opt-in Form on Single Post']);
</script>
<?php }
/*  END Add KISSMTRICS SCRIPT TO ONLY POSTS */

alturic on "$concat = str_split( $concat, 128 ); - Breaking scripts in the middle of names.."

$
0
0

I found this: https://core.trac.wordpress.org/ticket/26886#comment:7 and while the fix was marked as simply disabling concat I'm curious what bad can happen by literally changing $concat = str_split( $concat, 128 ); to $concat = str_split( $concat, 3000 );? Sure it'll get over-written on upgrades, etc but that literally fixed my problem, so I'm unsure if it's bad to just change that number and nothing else.

seedsca on "Adding content to specific Categories"

$
0
0

Fistly, I know enough to break things, and sometimes do what I want.

I am attempting to have 3 versions a table with links under #main show up depending on the category.

The table would be a set of icons with links that are pertinent to the category and would be placed imediately above the page's content.

Not sure how to wrangle this one. Maybe edit the archive.php file? An awesome plugin, or?

crankit on "Easy Media Gallery Pro - Creating Text Link to "Lightbox" Gallery Slider"

$
0
0

Hello----

So I am using Easy Media Gallery Pro -- great plugin, but didn't want to have a million gallery thumbnails flooding the pages. So, I wanted to created a text link where you could "Click Here" and the LightBox SlideShow would just pop up. I could not find info to achieve this online... So I started playing around with some code and I think I am pretty close to making this work...

I was able to link the "CLICK HERE" text and trigger the lightbox to pull up and even grab the first photo in the album ---however--- I cannot trigger the navigation arrows or initiate the slide show. I think I need to call out a javascript function??? But I am not sure... Any help would be greatly appreciated!

I looked through the javascript functions that are in the plugin and I did not find it to be very clear cut on which to use --- as I have very limited experience with it.

I setup a test page on the website---url: http://www.dinapariseracing.com/test
Click on the "CLICK HERE" link for 'The Build' to see the popup slideshow

Link to current Easy Media Gallery that we plan on replacing with the test gallery if we can get this code right: http://dinapariseracing.com/photos

The Code I have setup in the test page is as follows:
<a class="59668" href="http://dinapariseracing.com/wp-content/plugins/easy-media-gallery-pro/includes/class/timthumb.php?src=http://dinapariseracing.com/wp-content/uploads/final-contact.jpg&h=367&w=940&zc=1&q=100&a=c" target="_blank" rel="easymedia[gallery-59668]">CLICK HERE</a>

Again, any help greatly appreciated! Just trying to make this happen....

Deborah on "How to add a custom widget to my WP site"

$
0
0

Hi
I've been given the following link to add a custom built widget to my site (its a currency converter) and I've been told I can just paste this into my site and the widget will show.

http://partners.moneycorp.com/converterpio/?rp=10506843

As I suspected, just pasting this link doesn't work, so do I past the HTML code and then add the relevant CSS coding, should I go back to the developers for more information, or is there something else I should be doing?

I can do reasonable CSS and html code but when it comes to PHP I'm really limited.

Thanks


PropSculpt on "Woocommerce Add to Cart redirect to prompt email"

$
0
0

Hi all,

I have just set-up a website for a small business idea I’m wanting to test. (propellersculptures.com)

Essentially I want to redirect the WooCommerce “Add to Cart” button, so that instead of adding the product to the cart the user is directed to their email to send an enquiry form.

Below is the code I have setup in a custom function.php file. I just cant figure out how to get the button to remain and complete the redirect.

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

add_action( 'woocommerce_after_shop_loop_item', 'my_woocommerce_template_loop_add_to_cart', 10 );

function my_woocommerce_template_loop_add_to_cart() {
    global $product;
    echo '<form action="mailto:dchr24@hotmail.com" method="get">
            <button type="submit" class="single_add_to_cart_button button alt">Buy Now!</button>
          </form>';

I have had success redirecting with this code:

add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_to_cart_loop' );

function change_add_to_cart_loop( $product ) {
    global $product;

    return '<a href="mailto:dchr24@hotmail.com">Buy Now!</a>';
}

However I lose the button.

Hope that makes sense.

ckaden on "Add custom taxonomy terms to post metabox"

$
0
0

Hello,

I hope you can help me with my problem. I have created a custom taxonomy called "regionen" (english regions / my blog is about japan and this taxonomy organise posts by locations) which is visible under "posts" in the backend, like categories and tags. I can already attach them to posts without problems. I registered the taxonomy via functions.php:
https://gist.github.com/anonymous/9fdb9783c154c3f4c57a#file-functions-php-L16-L51

What I want to do now is to add the terms of the new custom taxonomy to the metabox between "categories" and "tags", like in this picture: https://theme-fusion.com/wp-content/uploads/gravity_forms/6-37ef8c212a7d20bf9d6038f419321ad0/2015/02/metabox.png

I already contacted the support of Avada (the theme I use), but they could provide me with pointers only:

1) "You will need to edit the following file in the theme folder:
Avada/framework/custom_functions.php
Look for function avada_render_post_metadata"
The mentioned file: https://gist.github.com/anonymous/6d89b73ca48e992af120#file-custom_functions-php-L1164

2)
"1. The follow is the code which sets for the single page:
if( $layout == 'single' ) { $html .= sprintf ( '%s', $metadata ); }
2. $metadata is the variable which stores the output. So you need to add your output to this.
So this line sets the output for the taqs:
$metadata .= sprintf( '<span class="meta-tags">%s %s</span><span class="sep">|</span>', __( 'Tags:', 'Avada' ), $tags );

So you want to add your taxonomy before this (shown by the // INSERT...):

}
$metadata .= sprintf( '%s<span class="sep">|</span>', $categories );
}
}
// INSERT YOUR CODE HERE, so $metadata .= "youroutput";
if( ! $smof_data['post_meta_tags'] ) {
ob_start();
the_tags( '' );
$tags = ob_get_clean();

if( $tags ) {
$metadata .= sprintf( '<span class="meta-tags">%s %s</span><span class="sep">|</span>', __( 'Tags:', 'Avada' ), $tags );
"

I appreciate andy help with this. I have no problems with HTML/CSS, but php is a closed book for me.

Article with metabox on my website: http://www.japan-kyoto.de/leica-der-hanamikoji-strasse-gion-kyoto/

nimh on "Plugin Development needing new page"

$
0
0

I've looked and googled but I'm not finding my answer, maybe someone here can point me in the right direction.

I'm attempting to code my first plugin, and I'm stuck at the moment.

The plugin's first page opens as expected, then I want to add some actions/links to that main page that will take the user to another screen for data entry to a database.

How can I do this?

plugin_basename( __FILE__ ) ."?action=edit

doesnt give me the desired effect, as i thought it would...
I think i need to get to "tools.php?page=myPlugin" and then add the "?action=edit", am I right?

Thank you for any help, let me know if i need to clarify anything.

swedx on "Help with Show Expire Date WP JOB Manager"

$
0
0

Hello

I have found an thread earlyer about making expire date showup

think Mike Jolley wrote this

If you override the templates using this method https://github.com/mikejolley/WP-Job-Manager/wiki/Template-overrides you can add the date in there yourself.

<?php echo ( $expires = get_post_meta( $post->ID, '_job_expires', true ) ) ? date_i18n( get_option( 'date_format' ), strtotime( $expires ) ) : '–'; ?>

but iam so awesome green and really dont have any clue how to do this

could be really nice to get an to do list 1,2,3,4 and so on

we would like to see an expire date when we see listings after filtering
and offcourse also when we look on single job page

Hope someone can help

From JobGrønland
Henrik Philippsen

bradgb on "Displaying Eternal Data - Not Posts"

$
0
0

I am creating a plugin that needs to display eternal data, not wordpress posts.

What I have done: registered rewrites so wp recognizes my archive/single URLs, hooked into template_include to direct it to use my template if the requested URL was one of mine, and then in the template I call a function to load the external data and display it in post/archive format.

This works fine as long as I dont switch templates. Unfotunately, there is a variation in twentyfourteen and twentyfifteen template structure, in which #content and #main are inverted.

TwentyFifteen: body > #page > #content > #primary > #main
TwentyFourteen: body > #page > #main > #primary > #content

This means that whatever one I code my plugin template for, it is broken in the other.

twentyfifteen/single.php:

get_header(); ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

		<?php
		// Start the loop.
		while ( have_posts() ) : the_post();

twentyfourteen/single.php

get_header(); ?>

	<div id="primary" class="content-area">
		<div id="content" class="site-content" role="main">
			<?php
				// Start the Loop.
				while ( have_posts() ) : the_post();

So my question(s) are:

  • Am I going about this the right way? Do you know of a better way to inject external data?
  • Why are twentyfifteen tags inverted? Is this not a bug? Because I checked going back to twentlyeleven, and they are all in the order ...#main > #primary > #content.
  • Is there a way to do this, without requiring including a template, so that it works on more sites? The templates are going to be problematic on each site the plugin is used on, for just such reasons. I would prefer to forgo including a template, and somehow hook into archive.php and single.php to display my content, given the URL matches one of my requests.

websitesdepot on "Logout without revealing hidden login url"

$
0
0

Hi, I'm essentially trying to tie into the logout process. I have the login page on a custom URL that's hidden. I want to have users who only see the front end of the site. They register and login with my own custom pages on the front end.

Pretend my custom login page is:

mysite.com/hidden-login

Using the default logout method would send someone here:
http://mysite.com/hidden-login?action=logout&_wpnonce=1156asdf6748a

I want something like:
http://mysite.com/?action=logout&_wpnonce=1156asdf6748a

Essentially, I just want to push the logout process to another place, preferably the home page. I've already tried getting the nonce and doing something like this in code, but it didn't log me out:

wp_specialchars(site_url('?action=logout&_wpnonce='.wp_create_nonce('log-out'), 'login'))

Any ideas?

jvboimonkiboi on "Pagination to carousel effect"

$
0
0

Hi everyone,

I'm currently building a new wordpress site and I badly need help when it comes to codes. I want my pagination to act like a carousel. Is that possible?

Upon clicking on a pagination, the page entirely loads including the other parts of the page. I just want the effect to act like a carousel wherein if i click on the next button or page, the items will just move to the next item and will not load the entire page and/or move to the next page.


jon.sig on "send_to_editor"

$
0
0

Hey guys,

I'm working on a plugin.
It creates a new media_upload_tab and runs a code where an image is added to the gallery with media_sideload_image.
Now I would like to put this image (the html code generated) in the editor where my cursor was (just like the standard image inserting function) and close the iframe.

Can you help me with this?
Is there a function to add code to the editor in the parent element?

Thanks,
Jonas

davidnmadu on "continuous loop page"

$
0
0

Hi all

Really hope someone can help me as I have been looking but can not seem to find the answer. Anyway I am new to all this and have a blog I'd like help with basically I would like my page to continuously scroll through the information I place there (text and images)

Kind regards
Dave

MFSAM on "Multiple post_types with the function count_user_posts"

$
0
0

Hi,

I see since 4.1 that this function allows you to see how many posts a user has published within custom post types.

For example, I can find out how many posts user 9 has published under the post type 'film' by using count_user_posts( 9 , "film" )

However, is there a way that I can get the count for all of his posts from all our post types combined rather than just the one?

Up until yesterday I had been using this...

$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
$args = array(
	'author' => $curauth->ID,
	'post_type' => 'any'
);
$posts = new WP_Query($args);
$post_count = $posts->found_posts;

That was until it stoped working for me in the application I need it to (page of authors).

Any help would be much appreciated,
Sam

candregg on "Function to exclude posts from feed by tag"

$
0
0

I'm looking for function code to selectively exclude posts to the feeds based on tag. I found the code below in a post from a couple of years ago, but cannot make it work (php newbie). I need to exclude posts with tag ID 740, but leave all the other posts alone.

Any help would be appreciated.

C

function exclude_tags_rss($query) {
	if ( $query->is_feed) {
		if( isset($_GET['tag__not_in']) ) {
			$qv = $_GET['tag__not_in'];
			if( strpos($qv, ',') !== false) $tag = explode(',', $qv);
			else $tag[] = $qv;
		}
		$query-> set('tag__not_in', $tag);
	}
return $query;
}
add_filter('pre_get_posts','exclude_tags_rss');

Shaped Pixels on "Edit Subdirectory stylesheets"

$
0
0

I noticed that the WordPress Codex http://codex.wordpress.org/Editing_Files states you can use the built-in editor to edit HTML, PHP, CSS, and TXT files. However, only PHP and the primary style.css shows up in the list.

But the main thing here is that I was planning to place a couple CSS files in a subdirectory of the theme /css/ but it's not finding them.

Is there something that can be done to have the editor show these extra CSS files, but also the HTML and TXT files (as it appears it's not).

Thanks in advance.

Note: Yes, all files are writable as this is local on my XAMPP

Viewing all 8245 articles
Browse latest View live


Latest Images