Viewing 7 replies - 16 through 22 (of 22 total)
  • Hi, I am new to writing plugins and hope you can help me understand this better.
    I just created a calendar plugin and it initially appears correctly so I think the paths are okay but I’m having trouble with the part that takes it to the next or previous month(s).
    Here are the relevant bits of my code:

    $today = getdate();
    	if(isset($_GET['mon'])){
       		if(isset($_GET['year'])) {
          		$start = mktime(0,0,0,$_GET['mon'],1,$_GET['year']);
       		} else {
        		$start = mktime(0,0,0,$_GET['mon'],1,$today['year']);
       		}
    	}
    	else {
       		$start = mktime(0,0,0,$today['mon'],1,$today['year']);
    	}

    ….

    if($month > 13) {
    		while($month > 13) {
    			$next=2;
    			$year++;
    		}}
    
     	if($month < 13) {
     		$next = $month + 1;
    	} 
    
    	$previous = $month-1;	
    
    	if($month < 1){
            while($month < 1){
               	$month+=12;//add a $year
                $year=$year-2;//subtract a $year
            }
    	}
    ...
     		$html .= '<a href="' . PATHTOPLUGIN. 'mypluginfile.php?mon='.$previous.'&year='.$year.'">previous</a>';

    When I click on the previous [month] link, I get the following error:
    Fatal error: Call to undefined function wp_enqueue_style() in /home/*****/public_html/wp-content/plugins/mypluginfolder/mypluginfile.php
    and the url looks like:
    https://mywebsite.com/wp-content/plugins/mypluginfolder/mypluginfile.php?mon=4&year=2013 so it looks like the right parameters are being sent?

    I don’t know enough to know where my problem is so I help someone in this forum will point me in the right direction. Thank you for any help!!

    Sorry, a little follow on… I’m using shortcode that I placed inside of a post. I don’t know enough about WordPress to know if that makes a difference. I created this calendar to be responsive so that whether it appears in a sidebar widget or post, it would fit. I don’t quite understand the implications of post versus template versus widget in terms of paths (if it has an impact) or possible required headers (I looked at wp events calendar and see it sends headers…) Again, thanks for your help!

    I dont really understand your question. Its better to show how you define “PATHTOPLUGIN” or are you having trouble to get the correct url?

    Moderator bcworkz

    (@bcworkz)

    @chrisvwlc, any php file that is directly linked to that wants to use WP functions needs to include ( or use some related function ) wp-load.php to load the WP environment.

    Next time, please start your own topic, your question will get much better exposure by doing so, and you also make the statistics collected by the forum admins more accurate.

    bcworkz is right. The script and error you have shown is very irrelevant or no connection with your question. Please start a new thread with proper question.

    I have a relevant question.

    If at the top of my target page I execute this:
    print_r( $wp_query->query_vars);

    I can see a list of the valid query_vars … nice. However, if I actually use any one of them (like author_name), the target page redirects to 404.php. Why is that?

    The only way to make it work is to use a parameter that is NOT in the approved list and that seems the opposite of the intention.

    For example, I set up a test …

    1. Construct these links in the page you want to link from:

    https://example.com/target-page/?author_name=joeuser
    https://example.com/target-page/?author_name_alt=joeuser

    2. Then on that target-page use:

    $author = $_GET['author_name'];

    or

    $author = $_GET['author_name_alt'];

    The target-page using the existing ‘author_name’ var returns 404.php, but the alternate, made-up var name works (accepting the url parameter). There is obviously something special about the way wordpress handles that list of query_vars.

    What is the point of having query_vars then?
    What am I missing?

    Edit: I just noticed that the resulting 404.php “not found” page url now has the parameter value embedded like this:

    https://example.com/target-page/joeuser

    hmmm, the plot thickens. Does wordpress have an internal redirect thing going on?

    Moderator bcworkz

    (@bcworkz)

    Hi Ron – Even though your question may be related, you still should create a new topic, it is the preferred practice and your question will be read by more people who may be able to answer.

    Query vars are used to construct queries, nothing more. Attempting to use them for other purposes such as URL parameters exceeds their intended use. It may seem like the same thing, but query vars are constructed for queries based on URL parameters, they are not necessarily valid URL parameters. The are for queries, not page requests.

    And yes, WP does its own 404 handling. The file system cannot know if page requests are valid since the data is in the DB, not the files. Have a look at Query Overview for more information.

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘How to pass value in wordpress url’ is closed to new replies.