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

accuratelimited on "Custom Post Type placed in Category - Using pre_get_posts causes problems"

0
0

Hi Guys, This is a tough one.

I have created a custom post type, in this case, 'referee' for a referee website. And I want them to appear in category archives.

This is easy thanks to (https://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/):

function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'nav_menu_item', 'my-custom-post-type'
		));
	  return $query;
	}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

However, in the sidebar I want to display a list of the referees from another query. By using the above or similar code that suppresses filters, the code then returns normal posts that I don't want when on a category page (i.e. Whilst it might luckily show a referee it is mostly normal posts).

<?php

$args = array( 'post_type' => 'referee', 'posts_per_page' => $noc, 'post_status' => 'publish' );
$refereeshow = new WP_Query( $args );

while( $refereeshow->have_posts() ) : $refereeshow->the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'small-thumb', array('title' => get_the_title()) ); ?></a>
<?php } else { ?>
	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img  src="<?php echo get_template_directory_uri(); ?>/images/mini-thumbnail-default.jpg" alt="<?php the_title(); ?>" /></a>
<?php } ?>
<?php the_title( sprintf( '<h1><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?>
<?php
endwhile;
wp_reset_query(); ?>

Is it possible to ensure either the pre-get-posts isn't used on the second query or can anyone suggest another way to accomplish the task?


codeguerrilla on "Grab posts from recently created category"

0
0

Hello. I have an interesting problem that I could use some help resolving.

I need to know if there is a way to grab posts from the most recently created category.

My client needs to add a new category each month. The category is actually the month and year. Think of a magazine, where for example the current issue(Category) is March 2015. They will create a new issue(Category) each month, and of course articles will be posted in sub categories of the current issue(Category).

How can I grab posts from the most recently created category for each month?

Any help would be very much appreciated.

NelutuO on "Post type tree loop"

0
0

Hi.

I need to get the pages of a custom post type exactly as they are in the admin panel.
Example:

Page1
--subpage1
--subpage2
Page2
Page3
--subpage1
--subpage2

I need this as a loop.

I tried for a few days to do this but no success.

Can anyone help me? Thank you. Neluțu.

SteveHale on "SIngle Page Password Problems"

0
0

Hi all

I have a single page passworded on my site. However the WP password protection does not seem very safe because after a user has logged into the page to see the content they can just keep going back to the page, even after closing the browser.

I have looked this up and can see many past posts about the password being stored for 10 days as a cookie and I have found posts that advise about hacks and then finally I found that in v 3.7 or WP control was added to the wp-login.php file to allow cookie timeout changes.

However my problem appears to be that even though I have changed the wp-login.php file to zero - i.e. every session must produce a login, it does not seem to work and I am wondering if I have made the change correct.

The article I read said this section is the part that needs changing:-

/**
	 * Filter the life span of the post password cookie.
	 *
	 * By default, the cookie expires 10 days from creation. To turn this
	 * into a session cookie, return 0.
	 *
	 * @since 3.7.0
	 *
	 * @param int $expires The expiry time, as passed to setcookie().
	 */
	$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
	$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
	setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );

This starts about line 467.

So I changed this part: time() + 10 * DAY_IN_SECONDS to:

time() + 0 * DAY_IN_SECONDS

as the notes seem to suggest that is what to do.

However if I change this to zero the password protection for the page does not work at all. Also the other thing is that, presumably, each time there is an update the wp-login.php file will be replaced, meaning having to change it each time.

The site is here: http://www.farnhamscouting.com and as this is a charity and the passworded page is a list of members I only want members to see the content but, as has been said many times in other posts about this, if the page is viewed from an internet cafe or public computer then it seems open to the world!

Can anyone provide any helps/ideas how to get the password expiry to work in wp-login.php properly?

Cheers

SteveB

realgigex on "How do i access my gateway class i made in WC"

0
0

First of all to clerify im a beginner in php.
I created a custom gateway class for WooCommerce following this instructions page: http://docs.woothemes.com/document/payment-gateway-api
I cant understand how to access my class in a different method. do i need to create an instance of it? is it created when my plugin is activated? how do i access it?

These are the declarations in my code (i removed the contents, since it is not important for this question):

add_action( 'plugins_loaded', 'myClassInit' );

	function myClassInit()
	{
		class MyClass extends WC_Payment_Gateway
		{
			public function __construct()
			{
				//set properties
			}

			function init_form_fields()
			{
				// define fields
			}

			function process_payment( $order_id ) {
				//do stuff
				return;
			}
		}

		function myclassAdd( $methods ) {
			$methods[] = 'MyClass';

			return $methods;
		}

		add_filter( 'woocommerce_payment_gateways', 'myClassAdd' );
	}

7Farmgirls on "Sidebar Is Under Posts in Chrome and IE"

0
0

I'm not sure exactly what has happened...or when it happened, but sometime after I created a new menu (a footer menu and another header menu), my sidebar gets bumped under the posts when you view it in Chrome, or IE. It looks great in Firefox :)

Looks like this:
http://sevenfarmgirlsisters.com/wp-content/uploads/2015/03/Blog.jpg

I've looked for extra <div> tags, I've deactivated and reactivated all of my plugins, I've read and read and read and can't figure out what I did wrong :P :)

I have a Child Theme of 2012 that I've been working on. I installed the Parent 2012 and the sidebar is where it's supposed to be. When I installed my Child 2012, it went back to being messed up, so clearly it's something I did :)

Maybe it has nothing to do with the menus, I don't know, but that's about the same time I started noticing that.

Thank you for any help!

The site I'm working on is http://cathyflorence.com

ottmance on "Using a jQuery accordian on a widget."

0
0

First things first, I'm new to PHP and the Wordpress API, despite that fact I've managed to write a fairly involved widget that does exactly what I set out to make it do.

However it suffers in the UI department. My issue is that I have nearly 40 options to select/set and that makes the settings screen quite long, think "scroll of death". It's possible to divide the options into 4 distinct sections and I'd like to be able to get those sections into something like an accordion control to limit the vertical scrolling. Something like this would do nicely . Is this possible? Does it go against any Wordpress UI rules?

Thanks
Chuck

U4EA on "Editing final page output from a cache page (need to use REGEX)"

0
0

Hi folks,

I REALLY hope someone can help me with this.

I currently have a Wordpress/Woocommerce site which is using page caching. The page caching is great, the only downside to it being that the cart widget in the top of the page is also being cached, meaning that is a user revisits a page after they have gone to a Woocommerce page and added a product to the cart, they are still shown the cached version of the page and the cart info is out of date.

I know how to call the Woocommerce functions to return the HTML and how to use REGEX to replace it in the HTML document. So what I need is a way where I can use a hook to get the cached page and run it through the REGEX in order to replace the cart fragment.

Can anyone help me with this?


jbowyers on "Passing Multidimensional arrays and Associative arrays to plugin shortcodes"

0
0

I want to pass complex structured data to a plugin I am creating. I have been using text strings in shortcodes with delimiters that are exploded into arrays by the plugin but things get increasingly more complex with multidimentional arrays and nested associative arrays. Here is an example of a shortcode:

[shortcode columns="Column Name 1: string:domain, Column Name 2: number: data" rows="r1c1: 12, r2c1: 22" options="option1: suboption1; value1 | value2, option2: suboption1; value1| value2"]

Is there a better way to do this?

Yudhistira Mauris on "Should I use WP postmeta or create a custom table?"

0
0

Hello,

I am developing a plugin that creates a custom post type to store some data. The data of each post is quite big, around 20-30 rows. Should I use postmeta table to store the data or create a custom table to store the data?

Thank you,
Mauris

Mike Howard on "How to Handle 'Journaling'"

0
0

This may be more of a request for advice than anything...

I want to add a Journaling function into my plugin whereby all actions are logged. My initial thought was to use comments as it seemed to be the most logical solution and meets my requirements. However, I keep running into the duplicate comment error - Is there a way to bypass this filter? I am currently using wp_new_comment($data) to insert the comments but as many entries will be from the same author/email and related to the same post the duplication filter is getting in my way - I need to ensure no other plugins filter this either...

Or is a better way to do this to create child posts? Or is there any other recommendations?

Thanks

Marius62 on "Search result page to a real page with slugid and page name"

0
0

I want the wordpress search result redirected into a real page with a name and slugid. Is this possible? I created a searchpage.php template, and created the Page called mysearch and added the template to it , but it still goes to default result page.

the code i used for searchpage.php

<?php
/*
Template Name: Search Page
*/
get_header(); ?>

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

			<?php if ( have_posts() ) : ?>

				<header class="page-header">
					<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'catcheverest' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
				</header><!-- .page-header -->

				<?php catcheverest_content_nav( 'nav-above' ); ?>

				<?php /* Start the Loop */ ?>
				<?php while ( have_posts() ) : the_post(); ?>

					<?php get_template_part( 'content', 'search' ); ?>

				<?php endwhile; ?>

				<?php catcheverest_content_nav( 'nav-below' ); ?>

			<?php else : ?>

				<?php get_template_part( 'no-results', 'search' ); ?>

			<?php endif; ?>

			</div><!-- #content .site-content -->
		</section><!-- #primary .content-area -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

second solution could be:
It would be nice if ther was a way to give the search result page a name and slug id.

Can someone please help me?

Thanks in advance

wzshop on "Custom field to custom taxonomy term?"

0
0

I have this script to save a custom field as a custom taxonomy term. All is working fine, but I would like to extend it a little bit, so that multiple values in the same custom field (seperated by a comma) are saved as different custom taxonomy terms. In example: in a custom field i write 'value 1, value 2'. I would like those 2 values to be separately saved as a custom taxonomy term. Is there anyone who has a solution for this, based on my code below?

//Custom field to custom taxonomy script
    $input_terms = array();
    $input_terms[] = sanitize_text_field( $_POST['customfieldname1'] );
    $input_terms[] = sanitize_text_field( $_POST['customfieldname2'] );
    $terms = array();

    foreach( $input_terms as $term ) {

     $existent_term = term_exists( $term, 'mycustomtaxonomy' );

        if( $existent_term && $existent_term['term_id'] ) {

            $term_id = $existent_term['term_id'];

        } else {

    $term = wp_insert_term(
    $term, // the term
      'mycustomtaxonomy', // the taxonomy
      array(
        'description'=> 'This is '.$term.'!',
        'slug' => $term
      )
    );

    if( !is_wp_error($term ) && $term['term_id'] ) {
                 $term_id = $term['term_id'];
            }

       }
    //Fill the array of terms for later use on wp_set_object_terms
       $terms[] = (int) $term_id;

    }
    wp_set_object_terms( $listing_id, $terms, 'mycustomtaxonomy' );
reset();

rkoller on "Whats a proper way to send a warning/error in a transition_post_status hook?"

0
0

I have an issue i am unsure what the best way to solving it is. I even am uncertain if the used hook is the right one for the task. Basically my goal is the following: I want to check every post if it changes status and in case the new status is set to publish i want to perform a few conditional checks. If certain conditions are met the status should be changed to publish if the conditions aren't met the status shouldn't be updated and an warning/error/admin_notices should be shown.

I haven't figured out the conditional logic yet completely but even if i check only for the new status and place an echo, var_dump or a admin_notices function call inside i get "Cannot modify header information" cuz the http page headers are already sent.

function abc_attachment_check( $new_status, $old_status, $post ) {
    if( $new_status === 'publish' ) {
        $media = abc_attachments( $post->ID );
        var_dump($media);
    }
}
add_action( 'transition_post_status', 'abc_attachment_check', 10, 3 );

So my question is is the transition_post_status action the apropriate hook or should i go with another one? and what would be a proper way to go with the warning and error message call and display? Cuz i am kind of lost what the best choice would be. :/ Thanks Ralf

gerard749 on "Prevent users from changing e-mail address"

0
0

Hi,

I am trying to prevent users from changing there e-mail address the same way the username can't be changed in the profile edit screen without preventing the user from changing there display name or password.

I have tried function.php and a plugin without success. Can this be done.

Thank you for your help.

Jerry


Batyu-vitez on "use international characters to slug"

0
0

I would like to use international (i.e. Hungarian) characters in slug. I have a domain e.g. ár.hu. I would like to write post eg. "jövö" and give it the following url: "ár.hu/jövö/".

How is it possible? Which core function removes international characters from slug?

HackYaaaaa on "10, 2 50, 2 driving me nuts!!!"

0
0

add_login_logout_to_menu', 50, 2 );

add_login_logout_to_menu', 10, 2 );

I've searched the web & Codex trying to make sense of what these numbers represent.

Does anyone one know what's the difference between 50 vs. 10?

Nobody explains this. Is this some sort of a mystery that never gets explained?

lol, but seriously, I just want to know.

UnLambda on "New user profile "mother-tongue" custom field with flags ?"

0
0

Hi!
How to add a mother-tongue custom field with country flag image or (if it is not too complicated) and with text value (french or italian)? With plugins can help with that problem ?

wpkd on "Auto create tags with RSS Multi import"

0
0

Dear experts,

I am using the plugin "RSS Multi Import" to grab content from an RSS-feed and import it into my database. Since this is an automated proces, I do not physically click on any button before a post is published. And because this is automated, I never get a chance to add tags to the post before it is published. If I want to add tags to my posts, I need to edit each single post manually and create the tags.

There are plugins that can automatically write tags, based on title or content. However, these plugins all bind to the "edit" button. With over a 1000 posts each day, I can not manually click [EDIT] for every post and create tags that way.

I would like my posts to automatically have each word of the content as a seperate tag on auto-publish. Through a custom PHP-script that I wrote, I can remove tags based on an array of "bad tags".

This script can be run trough CRON so that bad tags get removed frequently. The content of my posts is limited to the first two sentenses, so the amount of tags per post is limited as well.

I checked wp_post_set_terms, but that use existing posts based on post_id. Is there any other way that I can have RSS Multi Import create tags directly on publish?

Any help is much appreciated!
Regards, KD

baileev2 on "Archive Setup"

0
0

Hello!
Thanks to anybody who responds.
So I started a Word Press site (sorry but I can't show it)with VERY VERY VERY limited plugins. I will have to rely heavily on code which I also know very very little about.

I did a newsletter and now I am trying to set up an archive for my first edition because I have to put up a second edition soon.

I set up an a new page with full width contact and an archive template. On the Archive Page, I want a left side (sidebar maybe) list of the pages. And in the body, hopefully the links in the left side bar will populate the body.

I hope this makes sense and somebody will be able to help.

Viewing all 8245 articles
Browse latest View live




Latest Images